Skip to main content

New Relic Logs

Log Streaming to New Relic

Following the general pattern for log streaming from applications running on CloudFlow, in this guide we give specifics for New Relic.

Obtain the following information from your instance of New Relic:

  • NEWRELIC_LICENSE_KEY: Learn about New Relic API Keys.

Deployment

The following deployment will run the Fluentd log forwarder in your CloudFlow project, gathering logs from other pods in that same project. Substitute NEWRELIC_LICENSE_KEY accordingly.

newrelic-logs-deployment.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: fluentd
section.io/logstream-destination: "true"
name: fluentd
namespace: default
spec:
ports:
- name: fluentdudp
port: 5160
protocol: UDP
targetPort: 5160
selector:
app: fluentd
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: fluentd
namespace: default
labels:
app: fluentd
spec:
replicas: 1
selector:
matchLabels:
app: fluentd
template:
metadata:
labels:
app: fluentd
section.io/logstream-collect: "false"
spec:
containers:
- name: fluentd
image: ghcr.io/section/fluentd-newrelic:master
imagePullPolicy: Always
resources:
requests:
memory: "200Mi"
cpu: "200m"
limits:
memory: "200Mi"
cpu: "200m"
volumeMounts:
- name: config
mountPath: /fluentd/etc/fluent.conf
readOnly: true
subPath: fluent.conf
volumes:
- name: config
configMap:
name: fluent-conf
---
apiVersion: v1
kind: ConfigMap
metadata:
name: fluent-conf
namespace: default
data:
fluent.conf: |-
<source>
@type udp
tag all_cloudflow_logs
<parse>
@type json
</parse>
port 5160
message_length_limit 1MB
</source>

<filter all_cloudflow_logs>
@type record_transformer
<record>
offset ${record["log"]["offset"]}
</record>
enable_ruby true
remove_keys log
</filter>

<match all_cloudflow_logs>
@type newrelic
license_key NEWRELIC_LICENSE_KEY
</match>

Apply the above resources with kubectl apply -f newrelic-logs-deployment.yaml into the same project where the pods to be logged are running.

View Logs in New Relic

Login to your New Relic account in order to see your logs.