最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

prometheus - How to calculate a device uptime in the last 24h and overall for the whole month - Stack Overflow

programmeradmin1浏览0评论

I am trying to calculate in Grafana the time a device was up in the last 24h and then in a monthly basis. Ideally it should be 2 panels, one for 24h and one overall for the month.

The query I am using currently is: avg_over_time(up{instance="***.***.***.**:****"}[24h]) * 100.
I copied it from the internet and I would like to do something similar for a month? Is this possible to achieve and if so, any pointers how to start?

I am trying to calculate in Grafana the time a device was up in the last 24h and then in a monthly basis. Ideally it should be 2 panels, one for 24h and one overall for the month.

The query I am using currently is: avg_over_time(up{instance="***.***.***.**:****"}[24h]) * 100.
I copied it from the internet and I would like to do something similar for a month? Is this possible to achieve and if so, any pointers how to start?

Share edited Feb 10 at 14:03 markalex 13.4k3 gold badges13 silver badges43 bronze badges asked Feb 10 at 13:46 Prodromos KoliopoulosProdromos Koliopoulos 1 2
  • 1 What is the problem here? In what way does result of the same query, but with 24h replaced by 30d, miss your expectation? – markalex Commented Feb 10 at 14:00
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Feb 11 at 4:56
Add a comment  | 

1 Answer 1

Reset to default 1

The avg_over_time function is documented here.

avg_over_time(range-vector): the average value of all points in the specified interval.

According to the range-vector documentation:

Range vector literals work like instant vector literals, except that they select a range of samples back from the current instant.

Whatever period (1s, 1m, 1h, 1d ...) you put in [] in a range-vector is the past period (24h is the last 24 hours, 7d is the last 7 days)

Now, you look at the instant vector literals, documented just above range vector literals.

Instant vector selectors allow the selection of a set of time series and a single sample value for each at a given timestamp (point in time).

You already have your query for 24h:

avg_over_time(up{instance="<identifier>}[24h]) * 100

So you just need to change the period from 24h to 30d, your query for a 30 day period becomes:

avg_over_time(up{instance="<identifier>"}[30d]) * 100

For periods, you use y,w,d,h,m,s,ms (year, week, day, hour, minute, second, millisecond).

Note: 6m does not mean 6 months but 6 minutes.

发布评论

评论列表(0)

  1. 暂无评论