Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.localops.co/llms.txt

Use this file to discover all available pages before exploring further.

A complete walkthrough of instrumenting a Node.js service using the popular prom-client library. See the overview for the general approach.

1. Add the dependency

npm install prom-client

2. Register custom metrics and expose /metrics

collectDefaultMetrics enables Node.js runtime metrics (event loop lag, heap size, GC duration, active handles, etc.).
const http = require('http');
const client = require('prom-client');

const register = new client.Registry();
client.collectDefaultMetrics({ register });

const emailsSent = new client.Counter({
    name: 'emails_sent_total',
    help: 'Total number of emails sent',
    labelNames: ['status'],
    registers: [register],
});

http.createServer(async (req, res) => {
    if (req.url === '/metrics') {
        res.setHeader('Content-Type', register.contentType);
        res.end(await register.metrics());
        return;
    }
    res.statusCode = 404;
    res.end();
}).listen(9090);

emailsSent.labels('success').inc();
For Express apps, you can mount the metrics handler directly on your main app port using express-prom-bundle — it also automatically tracks HTTP request durations, status codes, and route labels.

3. Declare the metrics endpoint in ops.json

{
    "metrics": {
        "endpoint": "/metrics",
        "interval": 15,
        "port": 9090
    }
}

4. Visualize with a community dashboard

DashboardIDNotes
NodeJS Application Dashboard11159The most widely used dashboard for prom-client — event loop lag, heap, GC, handles, HTTP request rate.
NodeJS Applications Dashboard19062Modern alternative requiring Grafana >= 10.0, supports the full set of prom-client default metrics.
NodeJS Applications and Logs Dashboard20371Combines prom-client metrics with Loki logs for unified observability.
To import: in Grafana, go to Dashboards → New → Import, enter the dashboard ID, and select your LocalOps Prometheus data source. You’ll instantly see heap usage, event loop lag, GC pauses, active handles, and more. Your custom application metrics (emails_sent_total, etc.) can be charted alongside.