【发布时间】:2021-11-15 18:38:25
【问题描述】:
我在 nodejs 中使用prom-client 来发布/metrics 端点。我想监控随着时间的推移偶尔发生的不同数量的销售。
在 prometheus 中跟踪零星或不连续指标的最佳方法是什么?现有的指标类型似乎都不合适。
- 用于跟踪单个值 (
Gauge) 的基本 prometheus 指标类型面向连续数据(例如 CPU 速度或并发请求)。 -
Histogram指标可以捕获不连续的数据,但需要手动百分位数并且显然只估计分位数 (https://prometheus.io/docs/practices/histograms/#errors-of-quantile-estimation)。当指标服务器重新启动时,计数也会被清除。 -
Summary指标可以捕获不连续的数据,但“通常不可聚合” (https://latencytipoftheday.blogspot.com/2014/06/latencytipoftheday-you-cant-average.html)。
这是一个简单的设置,带有Gauge,显然没有捕获
import express from 'express'
import promClient, { Gauge } from 'prom-client'
export const someMetric = new Gauge({
name: 'some_metric',
help: 'Track some metric; type = [a, b, c]',
labelNames: ['one', 'two'],
})
const metricServer = express()
metricServer.get('/metrics', async (req, res) => {
console.log('Metrics scraped')
res
.set('content-type', 'text/plain')
.send(await promClient.register.metrics())
})
// intermittent callback that reports sales
service.onSale(value => {
// this will simply overwrite the previous sale :(
someMetric.labels('a', 'all').set(value)
})
metricServer.listen(9991, () =>
console.log(`???? Prometheus listening on http://localhost:9991/metrics`)
)
我目前的计划是创建一个新数据库,以在内部跟踪滚动的 24 小时平均销售额,然后将其作为单个连续指标公开给 prometheus。不过,除了 prometheus 的聚合功能之外,在内部保持滚动平均值似乎很尴尬。
【问题讨论】:
-
我无法评论 Prometheus,因为我不关心它并实现了 influxDB。但是,如果没有明确的数据类型可以帮助您,您当前的计划听起来很合理。我会考虑不使用平均值,而是使用移动总和。平均值是一个低通滤波器,您的“零星”数据看起来像是滤波器的高频尖峰。
-
为什么不随着时间的推移聚合?即使它们不是连续的,您仍然可以使用仪表。您的间隔应该足够大以捕获您想要的数据。
-
@juanecabellob 与 Prometheus 聚合还是在内部聚合?也许你可以解释一个完整的答案。谢谢!
-
@RaineRevere 在我这样做之前,您到底想跟踪什么数据?警报还是阴谋?
-
用于随时间绘制
标签: node.js prometheus prom-client