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}`)
})
- Why aren't many metrics seen at the
/metricsend-point? - This example refers to a histogram of duration of HTTP requests in ms. How do I create a metric for total HTTP requests per second? This blog post seems to use total HTTP requests per second; but, it does not explain how the metric changed from
http_requests_totaltohttp_requests_per_second. (Ignore the Kubernetes, EKS, FluxCD, auto-scaling and Go part of the blog.)
Why aren't many metrics seen at
/metricsend-point?Because, the
register.metricsreturns aPromisethat should beawaited. From another blog post.This worked.
How the metric changed from
http_requests_totaltohttp_requests_per_second?Here is a hint from this tutorial.