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.
// Require dd-trace
consttracer=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# defaultDD_DOGSTATSD_PORT=8125# defaultDD_DOGSTATSD_NON_LOCAL_TRAFFIC=true# if expecting external metrics
use_dogstatsd:true# defaultdogstatsd_port:8125# defaultdogstatsd_non_local_traffic:true# if expecting external metrics
You’ll also need to configure your application to use the agent’s DogStatsD collector: