Grafana 将多个计数器值合并到一个图中

Grafana merge multiple counters values into one graph

我尝试找到一种使用 Prometheus 和 Grafana 为我的 Flak 应用程序创建用户计数器的方法。

Flask 应用程序 运行 作为具有多个 worker 的 wsgi,并且还通过 ngninx 进行缩放(docker 缩放)。因此,我创建了一个带有不同标签的计数器。其中标签是 docker 容器的主机名。

我现在面临的挑战是如何在 Grafana 中将所有这些计数器组合成一个图形。

在这个例子中,我有两个进程,一个有 5 个调用,另一个有 2 个调用。 我不想看到两张图表,而是只想看到一张最终值为 7 的图表。

我尝试对所有值使用 sum,但这并没有给我想要的图表。

也尝试了 sum_over_timesum 但值也不正确。

使用不加总和也不能解决我的问题。

没有(工人)的总和(愤怒(xxx_total[$__rate_interval]))

你必须使用 sum by / without.

without removes the listed labels from the result vector, while all other labels are preserved in the output.

by does the opposite and drops labels that are not listed in the by clause, even if their label values are identical between all elements of the vector.

对于您的具体问题,应该是这样的:

sum without (worker) (xxx_total)

但是,您的计数器似乎没有正确加起来(可能是因为您在抓取之间执行了查询),因此您需要首先使用 sum_over_time 随着时间的推移单独汇总它们,然后对它们求和使用 without。 像这样:

sum without (worker) (sum_over_time(xxx_total[$__rate_interval]))

工作解决方案是sum without (worker)(sum_over_time(xxx_total[$__rate_interval]))

感谢@kaios 为我指明了正确的方向。