Menu
Grafana Cloud

Node.js integration for Grafana Cloud

Node.js is a JavaScript runtime environment that allows execution of JavaScript code outside a web browser.

This integration includes 1 useful alert and 1 pre-built dashboard to help monitor and visualize Node.js metrics.

Before you begin

This integration monitors a Node.js app that exposes metrics through prom-client.

In order for the integration to work, the prom-client should be installed and the default metrics should be enabled. Afterwards the metrics can be exposed under /metrics endpoint.

JavaScript
import express from 'express';
import { collectDefaultMetrics, register } from 'prom-client';

collectDefaultMetrics();

const app = express();

app.get('/metrics', async (_req, res) => {
  try {
    res.set('Content-Type', register.contentType);
    res.end(await register.metrics());
  } catch (err) {
    res.status(500).end(err);
  }
});

app.listen(4001, '0.0.0.0');

Install Node.js integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find Node.js and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Node.js metrics to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboard and alert to your Grafana Cloud instance, and you can start monitoring your Node.js setup.

Configuration snippets for Grafana Alloy

Simple mode

These snippets are configured to scrape a single Node.js instance running locally with default ports.

First, manually copy and append the following snippets into your alloy configuration file.

Metrics snippets

alloy
discovery.relabel "metrics_integrations_integrations_nodejs" {
	targets = [{
		__address__ = "localhost:4001",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_nodejs" {
	targets    = discovery.relabel.metrics_integrations_integrations_nodejs.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/nodejs"
}

Advanced mode

The following snippets provide examples to guide you through the configuration process.

To instruct Grafana Alloy to scrape your Node.js instances, manually copy and append the snippets to your alloy configuration file, then follow subsequent instructions.

Advanced metrics snippets

alloy
discovery.relabel "metrics_integrations_integrations_nodejs" {
	targets = [{
		__address__ = "localhost:4001",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_nodejs" {
	targets    = discovery.relabel.metrics_integrations_integrations_nodejs.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/nodejs"
}

To monitor your Node.js instance, you must use a discovery.relabel component to discover your Node.js Prometheus endpoint and apply appropriate labels, followed by a prometheus.scrape component to scrape it.

Configure the following properties within each discovery.relabel component:

  • __address__: The address to your Node.js Prometheus metrics endpoint.
  • instance label: constants.hostname sets the instance label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Node.js instance.

If you have multiple Node.js servers to scrape, configure one discovery.relabel for each and scrape them by including each under targets within the prometheus.scrape component.

Grafana Agent static configuration (deprecated)

The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.

Dashboards

The Node.js integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • Node.js

Node.js application overview dashboard

Node.js application overview dashboard

Alerts

The Node.js integration includes the following useful alerts:

AlertDescription
NodejsDownCritical: Node.js not up.

Metrics

The most important metrics provided by the Node.js integration, which are used on the pre-built dashboard and Prometheus alert, are as follows:

  • nodejs_active_handles_total
  • nodejs_active_requests_total
  • nodejs_eventloop_lag_p50_seconds
  • nodejs_eventloop_lag_p99_seconds
  • nodejs_eventloop_lag_seconds
  • nodejs_external_memory_bytes
  • nodejs_gc_duration_seconds_count
  • nodejs_gc_duration_seconds_sum
  • nodejs_heap_size_total_bytes
  • nodejs_heap_size_used_bytes
  • nodejs_heap_space_size_used_bytes
  • nodejs_version_info
  • process_cpu_seconds_total
  • process_cpu_system_seconds_total
  • process_cpu_user_seconds_total
  • process_resident_memory_bytes
  • process_start_time_seconds
  • up

Changelog

md
# 0.0.7 - November 2023

* Replaced Angular dashboard panels with React panels

# 0.0.6 - July 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.0.5 - December 2022

* Update mixin to latest
  - Add missing job selector to query

# 0.0.4 - October 2022

* Update mixin to latest version:
  - fix NodejsDown alert definition

# 0.0.3 - September 2022

* Update dashboard panels descriptions.

# 0.0.2 - October 2021

* Update mixin to latest version:
  - Update queries to use $__rate_interval

# 0.0.1 - December 2020

* Initial release

Cost

By connecting your Node.js instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.