Search code examples
filterprometheusdayofweekpromql

prometheus filter range vector by day_of_week


I use sub-queries to get hourly aggregated values for the last week for example: The number of http requests per hour over the whole last week, which will return 168 values in a range vector.

delta(http_server_requests_seconds_count[1h])[1w:1h]

Now I want to filter the value to return only the ones which are for a specific week day, lets say return only the 24 value from Monday. I found some hints about day_of_week, timestamp, bool expr, but I cannot combine them to get it working or maybe it is not possible? Something like:

delta(http_server_requests_seconds_count[1h])[1w:1h] bool day_of_week() == 1

Solution

  • It'd be more effficient to adjust your start/end time to only over the day, but you could do:

    (increase(http_server_requests_seconds_count[1h]) and on () day_of_week() == 1)[1w:1h]