Node.js Monitoring

Sysdig is able to monitor your node.js applications. We do this by linking a library to your node.js code, which then creates a server in the code to export the StatsD metrics.

Below is an example of a node.js application that exports metrics using the Prometheus protocol:

	  "name": "node-example",
	  "version": "1.0.0",
	  "description": "Node example exporting metrics via Prometheus",
	  "main": "index.js",
	  "scripts": {
	    "test": "echo \"Error: no test specified\" && exit 1"
	  "license": "BSD-2-Clause",
	  "dependencies": {
	    "express": "^4.14.0",
	    "gc-stats": "^1.0.0",
	    "prom-client": "^6.3.0",
	    "prometheus-gc-stats": "^0.3.1"


The index.js library function is shown here:

        // Use express as HTTP middleware
        // Feel free to use your own
        var express = require('express')
	var app = express()

        // Initialize Prometheus exporter
	const prom = require('prom-client')
	const prom_gc = require('prometheus-gc-stats')

        // Sample HTTP route
	app.get('/', function (req, res) {
	  res.send('Hello World!')

        // Export Prometheus metrics from /metrics endpoint
	app.get('/metrics', function(req, res) {

	app.listen(3000, function () {
	  console.log('Example app listening on port 3000!')

 You will need to add a appcheck in the dockerfile

FROM node:latest
ADD package.json ./
RUN npm install
ENV SYSDIG_AGENT_CONF 'app_checks: [{name: node, check_module: prometheus, pattern: {comm: node}, conf: { url: "http://localhost:{port}/metrics" }}]'
ADD index.js ./
ENTRYPOINT [ "node", "index.js" ]


and run the app like this:

docker build -t node-example
docker run -d node-example


Once the Sysdig agent is deployed it will automatically retrieve node.js metrics. Here is an example of key node.js metrics visible on the Sysdig Monitor UI under Metrics. 




Code and configuration examples 



Have more questions? Submit a request