X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=metrics.cpp;fp=metrics.cpp;h=f44ced2c15a66715977b352736122442c9ba4541;hb=ba675cdb4f3156d9906c72746b535f54a1aff800;hp=3fadb72907d9afdc5e2574269c57badd539eba6f;hpb=1836dccf699779d9092a75755cec96cea1734a2a;p=nageru diff --git a/metrics.cpp b/metrics.cpp index 3fadb72..f44ced2 100644 --- a/metrics.cpp +++ b/metrics.cpp @@ -75,6 +75,22 @@ void Metrics::add(const string &name, const vector> &labels types[name] = TYPE_HISTOGRAM; } +void Metrics::remove(const string &name, const vector> &labels) +{ + lock_guard lock(mu); + + auto it = metrics.find(MetricKey(name, labels)); + assert(it != metrics.end()); + + // If this is the last metric with this name, remove the type as well. + if (!((it != metrics.begin() && prev(it)->first.name == name) || + (it != metrics.end() && next(it)->first.name == name))) { + types.erase(name); + } + + metrics.erase(it); +} + string Metrics::serialize() const { stringstream ss;