How to filter repeated metrics?

  • What Grafana version and what operating system are you using?
    I use the online Grafana dashboard.

  • What are you trying to achieve?
    I connect my Prometheus metrics to Grafana via a server URL and configured a scraping interval of 60s. So all my metrics repeat every 60s, and I want to exclude all repeated metrics in my visualizations and count only the first, but I don’t know how. I added a “uuid” label to each metric, so it should be easy to identify duplicates.

  • How are you trying to achieve it?
    I tried to use some aggregation and range operations.

  • What happened?
    I got a count/sum of all metrics, including duplicates. Finally, I got the desired result by using the count_over_time operation, but I’m not sure this query works properly. Also, it should be inefficient to count so many values.

  • What did you expect to happen?
    I would be happy just to remove all duplicates before any calculation.

Here is a screenshot of the metrics; I would expect to have only the first point here.

1 Like

You’re using the visual query builder there. Try switching to the “Code” view, and then use a PromQL aggregation function. Which one to use depends on what kind of aggregation you’re trying to use, but easy would just be to use max().

Here’s a shot of a repeated “same value over and over” metric query, along with using max, which filters it down to just the largest value.

Don’t want max? Not the right answer? Use one of the other aggregation functions in PromQL

Thanks for your answer, @davidallen5, but aggregation methods, as I understand, don’t filter out duplicates. Here is an example: I have search_duration metrics with 5 unique metrics, each repeating every minute. After applying the max method, I got one unique metric repeating every minute. I want the opposite: 5 unique metrics without repetition.

(two lines are visible, but there are actually five.)