我正在使用 Prometheus 监控 NodeJS 应用程序。
创建这样的直方图
const histogram = new client.Histogram({
name: 'node_request_duration_seconds',
help: 'Histogram for the duration in seconds.',
buckets: [1, 2, 5, 6, 10]
});
现在我像这样调用 histogram.observe() 来监视对路径的请求'/'
const app = express();
app.get('/', (req, res) => {
//Simulate a sleep
var start = new Date()
var simulateTime = 1000
setTimeout(function(argument) {
// execution time simulated with setTimeout function
var end = new Date() - start
histogram.observe(end / 1000); //convert to seconds
}, simulateTime)
counter.inc();
res.send('Hello world\n');
});
现在的问题是我在 NodesJS 应用程序中有许多其他请求路径,所以为了监视每个请求路径,我是否应该手动编辑每个服务请求的函数。
或者
有没有其他方法可以让我们从外部对每个函数调用 histogram.observe() 而无需手动编辑?