nexogen-international / Nexogen.Libraries.Metrics

Library for collecting application metrics in .NET and exporting them to Prometheus
MIT License
61 stars 9 forks source link

Remove deprecated metric with a specific label. #31

Open mikalais opened 6 years ago

mikalais commented 6 years ago

First of all, thank you for your work!

It is a great feature to be able to create new metrics by just using a new label. However that would be great to be able to remove metrics with a specific deprecated label. Please see the following example.

this.Something = metrics.Gauge()
    .Name("something_items_total")
    .Help("Total number of items")
    .LabelNames("someLabel")
    .Register();
# HELP something_items_total Total number of items
# TYPE something_items_total gauge
something_items_total{someLabel="label1"} 5 1513340498878
something_items_total{someLabel="label2"} 2 1513340498878
...

At some point items labeled with "label1" becomes obsolete and therefore its metric.. I can reset it to 0, but cannot remove it :(

This is what I would like to see:

# HELP something_items_total Total number of items
# TYPE something_items_total gauge
something_items_total{someLabel="label2"} 2 1513340498878
...

Correct me if I am wrong and it is a misuse of metrics, however if I do not remove it, it becomes kind of a tiny memory leak :)

ahoka commented 6 years ago

It seems to be a misuse a bit (hard to tell without knowing the exact usage), but I see some validity in your use case. But when would you evict it? After a time? Not updating a while?