From: Steinar H. Gunderson Date: Thu, 15 Jun 2017 15:21:56 +0000 (+0200) Subject: Fix a problem where Prometheus cannot handle negative NaNs. X-Git-Tag: 1.6.1~45 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=feb07ea6a1db70233e8928cf2732b2fc15020ab0;p=nageru Fix a problem where Prometheus cannot handle negative NaNs. --- diff --git a/metrics.cpp b/metrics.cpp index f44ced2..fafc389 100644 --- a/metrics.cpp +++ b/metrics.cpp @@ -118,7 +118,13 @@ string Metrics::serialize() const 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); }