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

风流意气都作罢 提交于 2019-12-11 15:57:56

问题


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="..."})

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 ?

Thanks in advance !

Mathias


回答1:


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.

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. You may need to adjust it to your timezone.



来源:https://stackoverflow.com/questions/53059856/how-to-get-the-average-over-time-only-during-the-day-in-prometheus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!