Node.js

Overview

The Node.js integration allows you to collect and monitor your Node.js application logs, traces, and custom metrics.

Setup

Metric collection

The Node.js integration enables you to monitor a custom metric by instrumenting a few lines of code. For instance, you can have a metric that returns the number of page views or the time of any function call.

For additional information about the Node.js integration, see the guide on submitting metrics.

// Require dd-trace
const tracer = require('dd-trace').init();

// Increment a counter
tracer.dogstatsd.increment('page.views');

Note that for custom metrics to work you need to enable DogStatsD on the Agent. Collection is enabled by default, but the Agent only listens for metrics from localhost. To allow external metrics, you need to either set an environment variable or update the config file:

DD_USE_DOGSTATSD=true # default
DD_DOGSTATSD_PORT=8125 # default
DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true # if expecting external metrics
use_dogstatsd: true # default
dogstatsd_port: 8125 # default
dogstatsd_non_local_traffic: true # if expecting external metrics

You’ll also need to configure your application to use the agent’s DogStatsD collector:

DD_DOGSTATSD_HOSTNAME=localhost DD_DOGSTATSD_PORT=8125 node app.js

Trace collection

See the dedicated documentation for instrumenting your Node.js application for sending traces to Datadog.

Log collection

Available for Agent v6.0+

See the dedicated documentation to set up Node.js log collection for forwarding your logs to Datadog.

Profile collection

See the dedicated documentation for enabling the Node.js profiler.

Data Collected

Metrics

runtime.node.cpu.user
(gauge)
CPU usage in user code
Shown as percent
runtime.node.cpu.system
(gauge)
CPU usage in system code
Shown as percent
runtime.node.cpu.total
(gauge)
Total CPU usage
Shown as percent
runtime.node.mem.rss
(gauge)
Resident set size
Shown as byte
runtime.node.mem.heap_total
(gauge)
Total heap memory
Shown as byte
runtime.node.mem.heap_used
(gauge)
Heap memory usage
Shown as byte
runtime.node.mem.external
(gauge)
External memory
Shown as byte
runtime.node.heap.total_heap_size
(gauge)
Total heap size
Shown as byte
runtime.node.heap.total_heap_size_executable
(gauge)
Total executable heap size
Shown as byte
runtime.node.heap.total_physical_size
(gauge)
Total physical heap size
Shown as byte
runtime.node.heap.used_heap_size
(gauge)
Used heap size
Shown as byte
runtime.node.heap.heap_size_limit
(gauge)
Heap size limit
Shown as byte
runtime.node.heap.malloced_memory
(gauge)
Malloced memory
Shown as byte
runtime.node.heap.peak_malloced_memory
(gauge)
Peak allocated memory
Shown as byte
runtime.node.heap.size.by.space
(gauge)
Heap space size
Shown as byte
runtime.node.heap.used_size.by.space
(gauge)
Heap space used size
Shown as byte
runtime.node.heap.available_size.by.space
(gauge)
Heap space available size
Shown as byte
runtime.node.heap.physical_size.by.space
(gauge)
Heap space physical size
Shown as byte
runtime.node.process.uptime
(gauge)
Process uptime
Shown as second
runtime.node.event_loop.delay.max
(gauge)
Maximum event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.min
(gauge)
Minimum event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.avg
(gauge)
Average event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.sum
(rate)
Total event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.median
(gauge)
Median event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.95percentile
(gauge)
95th percentile event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.count
(rate)
Event loop iteration count where a delay is detected
Shown as execution
runtime.node.gc.pause.max
(gauge)
Maximum garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.min
(gauge)
Minimum garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.avg
(gauge)
Average garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.sum
(rate)
Total garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.median
(gauge)
Median garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.95percentile
(gauge)
95th percentile garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.count
(rate)
Number of garbage collections
Shown as garbage collection
runtime.node.gc.pause.by.type.max
(gauge)
Maximum garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.min
(gauge)
Minimum garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.avg
(gauge)
Average garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.sum
(rate)
Total garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.median
(gauge)
Median garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.95percentile
(gauge)
95th percentile garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.count
(rate)
Number of garbage collections by type
Shown as garbage collection

Troubleshooting

Need help? Contact Datadog support.

Further Reading

PREVIEWING: domalessi/ssi-best-practices