clear out a metric in prometheus

Viewed 439

I'm currently using a platform to store orders that changes through time. I'm using Prometheus to also scrape when an order is created or when it changes its status. Find an example of the object below.

order = {id: <id>, status : <ORDERED, LOADED, DELIVERED>, time: <time>}

In order to save the order into Prometheus, I'm doing the following.

prom_order.inc(order)

I'm currently using a counter. However, after some a while, the metrics API keeps tracks of very old records. Also, Prometheus will save orders with the same id and the different statues. So, if the order went from ORDERED to DELIVERED, it will appear 3 different times. I'm wondering if there is a better metric to use for this case. Probably a metric that only preserves the last state? Maybe a metric that goes to zero ? Is there a metric that can be reset when is no longer needed? Is it possible maybe to delete or decrease a metric based on one of the labelNames?

1 Answers

I think it will better to remove the label "status" (ORDERED, LOADED, DELIVERED) and use the value of the metric to indicate the status:

0 = ORDERED
1 = LOADED
2 = DELIVERED

BTW: Do you have a label called "time"? You could use the "timestamp" for this, couldn't you?

Related