From d43ead5a71e1185d73808a1576473f6df0d46e85 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 3 May 2023 17:16:06 -0700 Subject: [PATCH] peer latency histogram actually works now --- .../core/include/prometheus/histogram.h | 18 +++++++++--------- node/Metrics.cpp | 15 +++++++++++++-- node/Metrics.hpp | 2 +- node/Peer.hpp | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ext/prometheus-cpp-lite-1.0/core/include/prometheus/histogram.h b/ext/prometheus-cpp-lite-1.0/core/include/prometheus/histogram.h index ac558fa21..0afe41758 100644 --- a/ext/prometheus-cpp-lite-1.0/core/include/prometheus/histogram.h +++ b/ext/prometheus-cpp-lite-1.0/core/include/prometheus/histogram.h @@ -28,15 +28,9 @@ namespace prometheus { /// a data race. template class Histogram : public Metric { - - using BucketBoundaries = std::vector; - - const BucketBoundaries bucket_boundaries_; - std::vector> bucket_counts_; - Gauge sum_; - public: using Value = Value_; + using BucketBoundaries = std::vector; using Family = CustomFamily>; static const Metric::Type static_type = Metric::Type::Histogram; @@ -69,7 +63,7 @@ namespace prometheus { bucket_boundaries_.begin(), std::find_if( std::begin(bucket_boundaries_), std::end(bucket_boundaries_), - [value](const double boundary) { return boundary >= value; }))); + [value](const Value boundary) { return boundary >= value; }))); sum_.Increment(value); bucket_counts_[bucket_index].Increment(); } @@ -110,7 +104,7 @@ namespace prometheus { bucket.cumulative_count = cumulative_count; bucket.upper_bound = (i == bucket_boundaries_.size() ? std::numeric_limits::infinity() - : bucket_boundaries_[i]); + : static_cast(bucket_boundaries_[i])); metric.histogram.bucket.push_back(std::move(bucket)); } metric.histogram.sample_count = cumulative_count; @@ -119,6 +113,12 @@ namespace prometheus { return metric; } + private: + const BucketBoundaries bucket_boundaries_; + std::vector> bucket_counts_; + Gauge sum_; + + }; /// \brief Return a builder to configure and register a Histogram metric. diff --git a/node/Metrics.cpp b/node/Metrics.cpp index 8687a264b..64862fa7d 100644 --- a/node/Metrics.cpp +++ b/node/Metrics.cpp @@ -177,8 +177,19 @@ namespace ZeroTier { { "zt_network_outgoing_packets", "number of outgoing packets per network" }; // PeerMetrics - prometheus::CustomFamily> peer_latency - { "zt_peer_latency", "peer latency (ms)", {}}; + prometheus::CustomFamily> &peer_latency = + prometheus::Builder>() + .Name("zt_peer_latency") + .Help("peer latency (ms)") + .Register(prometheus::simpleapi::registry); +/* prometheus::CustomFamily>::Build( + prometheus::simpleapi::registry, + "zt_peer_latency", + "peer latency (ms)", + {} + ); + */ //{ prometheus::Metric::Type::Histogram, "zt_peer_latency", "peer latency (ms)", {}}; + prometheus::simpleapi::gauge_family_t peer_path_count { "zt_peer_path_count", "number of paths to peer" }; prometheus::simpleapi::counter_family_t peer_incoming_packets diff --git a/node/Metrics.hpp b/node/Metrics.hpp index c2c39f7f1..f78a0f157 100644 --- a/node/Metrics.hpp +++ b/node/Metrics.hpp @@ -108,7 +108,7 @@ namespace ZeroTier { extern prometheus::simpleapi::counter_family_t network_outgoing_packets; // Peer Metrics - extern prometheus::CustomFamily> peer_latency; + extern prometheus::CustomFamily> &peer_latency; extern prometheus::simpleapi::gauge_family_t peer_path_count; extern prometheus::simpleapi::counter_family_t peer_incoming_packets; extern prometheus::simpleapi::counter_family_t peer_outgoing_packets; diff --git a/node/Peer.hpp b/node/Peer.hpp index 53c9505bf..cafde0f5c 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -600,7 +600,7 @@ private: SharedPtr _bond; - prometheus::Histogram _peer_latency; + prometheus::Histogram &_peer_latency; prometheus::simpleapi::gauge_metric_t _alive_path_count; prometheus::simpleapi::gauge_metric_t _dead_path_count; prometheus::simpleapi::counter_metric_t _incoming_packet;