0

I need to turn prometheus irate function to sql language, and i cannot really find the calculation logic anywhere.

i have the following query in prometheus sql:

100 - (avg by (instance) (irate(node_cpu_seconds_total{job="node",mode="idle"}[40s])) * 100)

Let's say i have the following data for a cpu:

v  20     50     100     200     201      230   
----x-+----x------x-------x-------x--+-----x-----
t  10     20     30      40      50       60   
    |      <--     range=40s   -->|
                                  t   

My question is not really related to postgres, since i could solve this problem in sql if i would know what is the formula i should develop.

i understand that i have to get the last two datapoints difference and divide value_diff with time_diff:

(201-200)/(50-40), but how the 40s window comes into the picture? ((201-200)/(50-40))/40 ?

What would be the proper mathematical calculation for the above prometheus query?

And how i should do the same if i have 8 cpu data? I tried to search for documentation, but could not find any proper explanation what is going on behind.

Thanks

clairvoyant
  • 195
  • 1
  • 11
  • And making the query above as recording rule, and then using postgresql as remote write is not a solution for you? At this point, you would have this metric for free in pgsql. – Armatorix Aug 15 '19 at 13:13
  • i storing raw data in a postgres db, but it seems the calc is right now: ((201-200)/(50-40)) this is the result for the above irate part and timeframe only comes into picture if i dont have two data points within – clairvoyant Aug 16 '19 at 10:04

0 Answers0