Reputation: 2471
I am working with this example to make my NodeJs application expose Prometheus metrics. When I access the /metrics
endpoint, I don't see output. I am new to Prometheus or for that matter custom metrics in general.
Here is my attempt.
const express = require('express')
const promClient = require('prom-client')
const Registry = promClient.Registry;
const register = new Registry();
const app = express()
const port = process.env.PORT || 3000
const histogram = new promClient.Histogram({
name: 'hello_lb:http_request_duration',
help: 'Duration of HTTP requests in ms',
labelNames: ['method', 'status_code'],
buckets: [0.1, 5, 15, 50, 100, 500]
});
register.registerMetric(histogram);
app.get('/hello', (req, res) => {
const end = histogram.startTimer();
res.send('Hello World!')
end({ method: req.method, 'status_code': 200 });
})
// expose our metrics at the default URL for Prometheus
app.get('/metrics', (request, response) => {
response.set('Content-Type', promClient.register.contentType);
response.send(promClient.register.metrics());
});
app.listen(port, () => {
console.log(`App is up at ${port}`)
})
/metrics
end-point?http_requests_total
to http_requests_per_second
. (Ignore the Kubernetes, EKS, FluxCD, auto-scaling and Go part of the blog.)Upvotes: 1
Views: 2850
Reputation: 2471
/metrics
end-point?Because, the register.metrics
returns a Promise
that should be await
ed. From another blog post.
This worked.
// expose our metrics at the default URL for Prometheus
app.get('/metrics', (async (request, response) => {
response.set('Content-Type', promClient.register.contentType);
response.send(await promClient.register.metrics());
}));
http_requests_total
to http_requests_per_second
?Here is a hint from this tutorial.
Install the Prometheus Adapter and configure it to turn the metric from Prometheus into a per-second request rate (using PromQL) and expose that metric as myapp_requests_per_second through the Custom Metrics API
Upvotes: 4