Middle+
Tell us about your experience with monitoring and logging (Grafana, Kibana)
sobes.tech AI
Answer from AI
In Node.js projects, I used Grafana and Kibana for monitoring and logging, which allowed for real-time tracking of service status and quick incident response.
With Kibana, I analyzed logs, filtered errors, and identified anomalies in application performance. For log collection, I used the Elastic Stack (Elasticsearch, Logstash, Kibana), which provided centralized storage and convenient search.
Grafana was used for visualizing metrics collected via Prometheus or other sources. This helped monitor load, response times, and other key performance indicators.
An example of setting up a metric in Grafana for a Node.js application:
const client = require('prom-client');
const httpRequestDurationMicroseconds = new client.Histogram({
name: 'http_request_duration_ms',
help: 'Duration of HTTP requests in ms',
labelNames: ['method', 'route', 'code'],
buckets: [50, 100, 200, 300, 400, 500]
});
// Measure request processing time in middleware
app.use((req, res, next) => {
const end = httpRequestDurationMicroseconds.startTimer();
res.on('finish', () => {
end({ method: req.method, route: req.route ? req.route.path : req.path, code: res.statusCode });
});
next();
});
This approach allows for quick identification of bottlenecks and errors in Node.js services.