From 289f2316772b336b0117e52abe81163d70a1292e Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 3 May 2023 14:04:01 -0700 Subject: [PATCH] Adding peer metrics still need to be wired up for use --- node/Metrics.cpp | 6 ++++++ node/Metrics.hpp | 4 ++++ node/Peer.cpp | 9 +++------ node/Peer.hpp | 3 +++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/node/Metrics.cpp b/node/Metrics.cpp index 7c10540e5..1fabf9b2b 100644 --- a/node/Metrics.cpp +++ b/node/Metrics.cpp @@ -176,6 +176,12 @@ namespace ZeroTier { prometheus::simpleapi::counter_family_t network_outgoing_packets { "zt_network_outgoing_packets", "number of outgoing packets per network" }; + // PeerMetrics + prometheus::CustomFamily> peer_latency + { "zt_peer_latency", "peer latency (ms)", {{}}}; + prometheus::simpleapi::gauge_family_t peer_path_count + { "zt_peer_path_count", "number of paths to peer" }; + // General Controller Metrics prometheus::simpleapi::gauge_metric_t network_count {"controller_network_count", "number of networks the controller is serving"}; diff --git a/node/Metrics.hpp b/node/Metrics.hpp index a3efcc284..13df1e4d1 100644 --- a/node/Metrics.hpp +++ b/node/Metrics.hpp @@ -107,6 +107,10 @@ namespace ZeroTier { extern prometheus::simpleapi::counter_family_t network_incoming_packets; extern prometheus::simpleapi::counter_family_t network_outgoing_packets; + // Peer Metrics + extern prometheus::CustomFamily> peer_latency; + extern prometheus::simpleapi::gauge_family_t peer_path_count; + // General Controller Metrics extern prometheus::simpleapi::gauge_metric_t network_count; extern prometheus::simpleapi::gauge_metric_t member_count; diff --git a/node/Peer.cpp b/node/Peer.cpp index c46bdf9d2..daa663c4e 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -28,11 +28,6 @@ namespace ZeroTier { static unsigned char s_freeRandomByteCounter = 0; -char * peerIDString(const Identity &id) { - char out[16]; - return id.address().toString(out); -} - Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Identity &peerIdentity) : RR(renv), _lastReceive(0), @@ -55,7 +50,9 @@ Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Ident _directPathPushCutoffCount(0), _echoRequestCutoffCount(0), _localMultipathSupported(false), - _lastComputedAggregateMeanLatency(0) + _lastComputedAggregateMeanLatency(0), + _peer_latency{Metrics::peer_latency.Add({{"node_id", OSUtils::nodeIDStr(peerIdentity.address().toInt())}}, std::vector{1,3,6,10,30,60,100,300,600,1000})}, + _path_count{Metrics::peer_path_count.Add({{"node_id", OSUtils::nodeIDStr(peerIdentity.address().toInt())}})} { if (!myIdentity.agree(peerIdentity,_key)) { throw ZT_EXCEPTION_INVALID_ARGUMENT; diff --git a/node/Peer.hpp b/node/Peer.hpp index 427e78a58..37b77f0ad 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -598,6 +598,9 @@ private: int32_t _lastComputedAggregateMeanLatency; SharedPtr _bond; + + prometheus::Histogram _peer_latency; + prometheus::simpleapi::gauge_metric_t _path_count; }; } // namespace ZeroTier