简体   繁体   English

如何仅在白天在Prometheus中获得一段时间内的平均值

[英]How to get the average over time only during the day in Prometheus

I'm currently trying to get the average percentage usage of RAM in the last month with the following query : 我目前正在尝试通过以下查询获取上个月的RAM平均使用率:

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

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 ? 该查询正常运行,但是现在我想过滤掉夜间收集的值,以便获得白天的实际使用百分比:是否有可能获得仅在上午8点到下午8点之间收集的值的平均值?晚上8点?

Thanks in advance ! 提前致谢 !

Mathias 马蒂亚斯

Since you can't have a range with holes (ie 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. 由于您不能有一个有空洞的范围(例如,过去4周,但只有8 AM至8 PM),因此您需要创建一条记录规则,仅记录一天中的可用内存,然后在时间序列中计算avg_over_time由所述规则产生。

The rule is relatively easy to set up 规则比较容易建立

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

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. 另请注意,此表达式将过滤UTC 8 AM和8 PM UTC之间的样本。 You may need to adjust it to your timezone. 您可能需要将其调整为您的时区。

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

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