我正在尝试使用摘要指标,并且不安静地了解如何将summary.observe呼叫放在哪里?这是舞会客户端示例(您可以在npm上找到):
const client = require('prom-client');
const summary = new client.Summary({
name: 'metric_name',
help: 'metric_help'
});
summary.observe(10);
但是没有足够的信息来使用它。
const client = require('prom-client');
const summary = new client.Summary({
name: 'metric_name',
help: 'metric_help'
});
summary.observe(10); // do I put it here?
async myFunc(){
await this.serviceCall();
summary.observe(10); // or here?
}
有人有一个很好的例子/总结观察的解释吗?
答案 0 :(得分:1)
首先,让我们澄清一下summary是什么:摘要度量标准捕获事件中的各个观察值,并将其汇总为多个相关度量标准:
例如:如果您正在测量服务的响应时间:
首先,您创建提供以下内容的摘要指标
foobar_request_duration_seconds
对于每个请求,您将计算请求的响应时间-这是一个观察结果
当Prometheus抓取您的端点时,指标是根据观察到的响应时间测得的
foobar_request_duration_seconds_sum
:请求消耗的总秒数foobar_request_duration_seconds_count
:请求数(请注意,您可以计算总和)foobar_request_duration_seconds_seconds{quantile="0.1"}
:响应时间10%(...对于所有已配置的分位数均相同)我希望这可以帮助您理解prom-client documentation:
第一个示例显示了如何指示要计算的分位数
new client.Summary({
name: 'metric_name',
help: 'metric_help',
percentiles: [0.01, 0.1, 0.9, 0.99]
});
第二个如何限制测量窗口;此处,度量是在最近10分钟内计算的(使用5个存储桶-这会影响值的平滑):
new client.Summary({
name: 'metric_name',
help: 'metric_help',
maxAgeSeconds: 600,
ageBuckets: 5
});
回到您的问题,应该根据您所观察的内容调用observe()
方法。
如果您要测量serviceCall()
返回的某些数据,请将其提供给摘要
number_bytes_exchanged = await this.serviceCall();
summary.observe(number_bytes_exchanged);
如果您要计算服务呼叫所花费的时间
const observe_response_time = summary.startTimer();
await this.serviceCall();
observe_response_time();