本文介绍了如何仅在白天在Prometheus中获得一段时间内的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试通过以下查询获取上个月的RAM平均使用率:

I'm currently trying to get the average percentage usage of RAM in the last month with the following query :

100 - ((avg_over_time(node_memory_MemAvailable_bytes{instance="...",job="..."}[4w]) * 100) / node_memory_MemTotal_bytes{instance="...",job="..."})

查询工作正常,但是现在我想过滤掉夜间收集的值,以便获得白天的实际使用百分比:是否可以仅获取收集的值的平均值在8AM和8PM之间?

The query is working correctly, but now I would like to filter out the values that were collected during the night, in order to have a real usage percentage during the day : is it possible to get the average of the values collected only between 8AM and 8PM ?

提前谢谢!

Mathias

推荐答案

由于您无法在有漏洞的范围内(即过去4周,但只有8 AM至8 PM),因此您需要创建一条记录的规则仅记录白天的可用内存,然后在该规则产生的时间序列中计算avg_over_time.

Since you can't have a range with holes (i.e. last 4 weeks but only 8 AM to 8 PM), you'd need to create a recorded rule that records available memory only during the day, then compute an avg_over_time over the time series produced by said rule.

该规则相对容易设置

node_memory_MemAvailable_bytes
  and 
hour(timestamp(node_memory_MemAvailable_bytes)) >= 8
  and 
hour(timestamp(node_memory_MemAvailable_bytes)) < 20

,但最初不会包含任何历史记录,因此您必须等待几天,然后才能从中获取任何有意义的数据.另请注意,此表达式将过滤UTC 8 AM和8 PM UTC之间的样本.您可能需要将其调整为您的时区.

but it will not have any history initially, so you'll have to wait for a few days before you get any meaningful data out of it. Also note that this expression will filter for samples between 8 AM UTC and 8 PM UTC. You may need to adjust it to your timezone.

这篇关于如何仅在白天在Prometheus中获得一段时间内的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 00:23