Skip to content

Monitoring Node.js Applications with Prometheus

Professional

You can instrument your Node.js application with prom-client and let the Glouton agent scrape its /metrics endpoint.

Terminal window
npm install prom-client express

The snippet below defines a counter and exposes it on http://localhost:8080/metrics:

const express = require("express");
const client = require("prom-client");
const requestsTotal = new client.Counter({
name: "myapp_requests_total",
help: "Total number of processed requests.",
});
const app = express();
app.get("/", (req, res) => {
requestsTotal.inc();
res.send("Hello");
});
app.get("/metrics", async (req, res) => {
res.set("Content-Type", client.register.contentType);
res.end(await client.register.metrics());
});
app.listen(8080);

Configure Glouton to scrape your application by adding the following to /etc/glouton/conf.d/50-prometheus-metrics.conf:

metric:
prometheus:
targets:
- url: "http://localhost:8080/metrics"
name: "my_nodejs_application"
allow_metrics:
- "myapp_requests_total"

Restart the agent to apply the configuration. See Prometheus Monitoring for the full list of options, including Docker label auto-discovery and Kubernetes annotations.