types[name] = TYPE_HISTOGRAM;
}
+void Metrics::remove(const string &name, const vector<pair<string, string>> &labels)
+{
+ lock_guard<mutex> 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;
if (metric.data_type == DATA_TYPE_INT64) {
ss << name << " " << metric.location_int64->load() << "\n";
} else if (metric.data_type == DATA_TYPE_DOUBLE) {
- ss << name << " " << metric.location_double->load() << "\n";
+ double val = metric.location_double->load();
+ if (isnan(val)) {
+ // Prometheus can't handle “-nan”.
+ ss << name << " NaN\n";
+ } else {
+ ss << name << " " << val << "\n";
+ }
} else {
ss << metric.location_histogram->serialize(key_and_metric.first.name, key_and_metric.first.labels);
}