Search code examples
prometheusprometheus-node-exporter

Average CPU usage comparision for last and current week via prom query


Trying to explore the option of comparing the CPU usage of last and current week via prom query node_cpu_seconds_total

Let me know if anyone came across such scenario.


Solution

  • The following query shows the percentage of CPU usage now:

    100 - 100 * (avg by (group, instance, job) (irate(node_cpu_seconds_total{mode="idle"}[5m])))
    

    And the following one shows the same one week ago:

    100 - 100 * (avg by (group, instance, job) (irate(node_cpu_seconds_total{mode="idle"}[5m] offset 1w)))
    

    See more information about the "offset" modifier in the Prometheus documentation here.