Search code examples
prometheusgrafana

Is there a way of ignoring all values until a certain date


An metrics I'm observing was incorrect until a certain date. Is there anyway in grafana, with a prometheus source, to ignore all values until that date? Just as if the metric was renamed (but renaming it is unfortunately not possible).


Solution

  • You can use query like this

    my_metric
    and on() (
      (day_of_month() > 10 and month() == 7 and year() == 2023)
      or (month() > 7 and year() == 2023)
      or year() > 2023
    )
    

    to exclude all metric values before 2023.07.11.

    It utilizes functions day_of_month(), month() and year() of Prometheus to filter out values with inappropriate related values. Also notice, since mentioned functions produce vector without labels, we are using construct and on() to match them with original metric.

    If you need to cut value not on the midnight, you can add a couple more lines with hour() and minute() functions.


    Alternatively, if you have a timestamp of first moment when your metric become correct, you can use query

    my_metric and timestamp(my_metric) > 1688080414
    

    Where 1688080414 is a mentioned epoch timestamp.