Junior
Have you ever collected metrics in Prometheus, including business metrics?
sobes.tech AI
Answer from AI
Yes, I have experience collecting metrics in Prometheus, including business metrics.
For the frontend, client libraries are usually used, which allow collecting performance metrics, user actions, and business events. For example, you can collect:
- Number of clicks on important buttons
- Page load times
- UI errors
- Conversions and other business events
These metrics are sent to Prometheus via exporters or intermediate services.
An example of using the prom-client library in JavaScript:
const client = require('prom-client');
const clickCounter = new client.Counter({
name: 'button_clicks_total',
help: 'Number of clicks on buttons'
});
function onButtonClick() {
clickCounter.inc();
// other logic
}
// Exposing metrics at /metrics
const express = require('express');
const app = express();
app.get('/metrics', async (req, res) => {
res.set('Content-Type', client.register.contentType);
res.end(await client.register.metrics());
});
app.listen(3000);
Thus, it is possible to integrate business metric collection directly into the frontend and analyze them in Prometheus and Grafana.