Node.js Integration for Grafana Cloud
This integration monitors a Node.js app that exposes metrics through prom-client.
Use the walkthrough in Grafana Cloud to install the Node.js Integration, like in our Quickstart.
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.
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 was configured, you can proceed with configuring the agent.
Post-install configuration for the Node.js Integration
In the agent configuration file, the agent must be pointed to the Node.js app, such as nodejs-app:4001
in the example below, that exposes the /metrics
endpoint.
prometheus:
wal_directory: /tmp/wal
global:
scrape_interval: 15s
configs:
- name: integrations
scrape_configs:
- job_name: integrations/nodejs
static_configs:
- targets: ['nodejs-app:4001']
remote_write:
- url: http://cortex:9009/api/prom/push