You can monitor your Node.js-based applications using the Linux Agent and Netuitive StatsD server. All it takes is installing our agent and instrumenting your custom metrics, and then you'll be visualizing the performance of your Node.js applications.
- Set the statsd setting in the netuitive-agent.conf file to enabled = True.
# local statsd server [[[statsd]]] enabled = True
- Ensure Node.js is installed properly.
- StatsD requires a client library to push metrics, so you'll need to install a Node.js library. For this example, we'll be implementing the node-statsd-client. The open source community also has many Node.js libraries for StatsD that should all work with our agent.Note If the client library is installed locally, please be sure to have the Node.js web server in the same directory.
npm install node-statsd-client
- Import the client into your application file and specify the location of the Netuitive StatsD backend. By default, the Netuitive StatsD runs on localhost port 8125 (as specified in the /opt/netuitive-agent/conf/netuitive-agent.conf file).
var Client = require('node-statsd-client').Client; var client = new Client("localhost", 8125);
- Instrument your application code by calling the appropriate functions. Example(s) What follows are examples of how to create metrics using some of the types compatible with the node-statsd-client library:
// Counter Increment – Count occurrences of an event client.increment ('example.data.counterup', 1); // Counter Decrement – Subract values from metrics client.decrement ('example.data.counterdown', 1); // Timer – Measure the amount of time an action took to complete client.timing("example.data.timer", 250); // Gauge – Set an static value and compare against it to evaluate fluctuations client.gauge("example.data.gauge", 5);
These metrics will show up under the statsd node in the Metrics page like so:
- Save your application, and then restart your application and the Linux Agent.