简体   繁体   English

Prometheus:如何收集临时进程的内存消耗指标?

[英]Prometheus : How to collect metrics for memory consumption of temporary processes?

I have an application that spawns different processes asynchronously. 我有一个异步生成不同进程的应用程序。 When the process finishes, the response contains details of the process like memory consumed etc. I want to create metrics for the memory consumed by each process, based on the output. 当进程完成时,响应包含进程的详细信息,例如消耗的内存等。我想基于输出为每个进程消耗的内存创建度量。 (Note: This means I can only update the metric only after the process finishes) (注意:这意味着我只能在过程完成后才能更新指标)

From the Prometheus official document I found that Gauge is the correct metric for such a measurement, when values go up and down arbitrarily. 普罗米修斯的官方文件中,我发现,当值任意上升和下降时,仪表是进行此类测量的正确指标。 But the problem using Gauge is that the metric value stays there for ever. 但是使用Gauge的问题在于,度量标准值永远都保持在那里。 I want to track the value used by the process only for that instant of time. 我只想跟踪该时刻所使用的值。

When i plot the graph of Grafana, I see a steady line, when i only want a surge for an instant. 当我绘制Grafana的图形时,当我只想瞬时增大时,会看到一条实线。 Any suggestions to best solve this problem. 任何可以最好地解决此问题的建议。 Thanks ! 谢谢 !

For short-lived jobs that cannot be scraped normally using Prometheus, Prometheus provides the push gateway which allows you to push metrics. 对于无法使用Prometheus正常取消的短暂任务,Prometheus提供了推送网关 ,您可以通过该网关推送指标。

In your case, your short lived processes would push the reported metrics into the push gateway and Prometheus will handle the rest. 对于您而言,短暂的流程会将报告的指标推送到推送网关中,而Prometheus将处理其余部分。

As of now, this is my workaround: 到目前为止,这是我的解决方法:

I have created a metric of type Counter and I keep increasing the metric value by an absolute number(the actual memory consumed). 我创建了一个类型为Counter的度量标准,并不断将度量标准值增加一个绝对数字(消耗的实际内存)。

In Grafana I display the increase() every 1 minute. 在Grafana中,我每1分钟显示一次递增()。

If anyone has a more correct solution, please do tell. 如果有人有更正确的解决方案,请告知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM