]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use %g for formatting. It strips trailing zeroes (unlike %f) and will switch to
authorOtto <otto.moerbeek@open-xchange.com>
Tue, 8 Jun 2021 11:45:33 +0000 (13:45 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Tue, 29 Jun 2021 13:04:30 +0000 (15:04 +0200)
scientific notation for very small or large values. Also correct units for
sum and count.

pdns/rec_channel_rec.cc

index 2bd594f92d5ce979fb7312321bfc706983529589..5ed2f9ece52766f86eebcff5f08dc9d480ef8604 100644 (file)
@@ -1116,16 +1116,18 @@ static StatsMap toStatsMap(const string& name, const pdns::AtomicHistogram& hist
   const auto& data = histogram.getCumulativeBuckets();
   const string pbasename = getPrometheusName(name);
   StatsMap entries;
+  char buf[32];
 
   for (const auto& bucket : data) {
-    char buf[32];
-    snprintf(buf, sizeof(buf), "%.0e", bucket.d_boundary / 1e6);
+    snprintf(buf, sizeof(buf), "%g", bucket.d_boundary / 1e6);
     std::string pname = pbasename + "seconds_bucket{" + "le=\"" +
       (bucket.d_boundary == std::numeric_limits<uint64_t>::max() ? "+Inf" : buf) + "\"}";
     entries.emplace(make_pair(bucket.d_name, StatsMapEntry{pname, std::to_string(bucket.d_count)}));
   }
-  entries.emplace(make_pair(name + "sum", StatsMapEntry{pbasename + "sum", std::to_string(histogram.getSum())}));
-  entries.emplace(make_pair(name + "count", StatsMapEntry{pbasename + "count", std::to_string(data.back().d_count)}));
+
+  snprintf(buf, sizeof(buf), "%g", histogram.getSum() / 1e6);
+  entries.emplace(make_pair(name + "sum", StatsMapEntry{pbasename + "seconds_sum", buf}));
+  entries.emplace(make_pair(name + "count", StatsMapEntry{pbasename + "seconds_count", std::to_string(data.back().d_count)}));
 
   return entries;
 }