I have a gauge metric that tracks device_status (ON/OFF). I would like to determine how many seconds a device was ON for a given period (e.g., yesterday, the current week, or the current month).
For example, to calculate the ON time for the current week, I am using the following Prometheus query:
sum_over_time((device_status{device_id="101"})[604800s:1s] @1720368000)
Technically, the return value should be greater than or equal to the total seconds in the given period since it sums the value over time.
However, I am encountering inconsistencies in the results. Sometimes I receive a value of, for example, 6000 seconds, but other times it is 5200 seconds.
I don’t understand why the value varies and doesn’t always match the expected total seconds.
Could someone help me understand why this discrepancy occurs and how to ensure consistent results?