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 enables the agent to send metrics to Grafana Cloud. A useful pre-built dashboard is included to help monitor and visualization Node.js metrics.

Pre-install configuration for the Node.js integration

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

In order for the integration to work, the prom-client must be installed and the default metrics should be enabled. Once you’ve completed this step, the metrics can be exposed under /metrics endpoint.

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');

After the application is configured, proceed with configuring the agent.

Install Node.js integration for Grafana Cloud

  1. In your Grafana Cloud instance, click on Connections from the Home menu located near the top left-hand side of the page.
  2. Navigate to the Node.js tile and click on it to review the prerequisites.
  3. When you are ready, follow the steps on the Configuration Details page to setup Grafana Agent and start sending Node.js metrics to your Grafana Cloud instance.

Post-install configuration for the Node.js integration

The agent must be pointed to the Node.js app that exposes the /metrics endpoint.

Add the following snippet to your agent configuration file. Be sure to change target in the snippet according to your environment.

metrics:
  wal_directory: /tmp/wal
  global:
    scrape_interval: 60s
  configs:
    - name: integrations
      scrape_configs:
        - job_name: integrations/nodejs
          static_configs:
            - targets: ['nodejs-app:4001']
      remote_write:
        - url: http://cortex:9009/api/prom/push

Dashboards

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

  • Node.js Overview

Node.js application overview dashboard

image

Alerts

The Node.js integration includes the following useful alerts:

AlertDescription
NodejsDownCritical: Node.js not up

Metrics

The following metrics are automatically written to your Grafana Cloud instance by connecting your Node.js instance through this integration:

  • 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

Changelog

# 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.