From 499ed6d95e11452019cdf48e32ed4cd878c2705b Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 19 Apr 2023 17:01:36 -0700 Subject: [PATCH] testing out a labled gauge on Networks --- node/Network.cpp | 37 +++++++++++++++++++++++++------------ node/Network.hpp | 7 +++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/node/Network.cpp b/node/Network.cpp index b03f4b3d0..bd199ca99 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -538,19 +538,29 @@ static _doZtFilterResult _doZtFilter( } // anonymous namespace +std::string nwid_printf(int64_t id) { + char out[32] = {}; + sprintf(out, "%.16llx", id); + return std::string(out); +} + + +prometheus::simpleapi::gauge_family_t multicastGroupsFamily{"network_multicast_groups", "number of joined multicast groups"}; + const ZeroTier::MulticastGroup Network::BROADCAST(ZeroTier::MAC(0xffffffffffffULL),0); -Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *uptr,const NetworkConfig *nconf) : - RR(renv), - _uPtr(uptr), - _id(nwid), - _lastAnnouncedMulticastGroupsUpstream(0), - _mac(renv->identity.address(),nwid), - _portInitialized(false), - _lastConfigUpdate(0), - _destroyed(false), - _netconfFailure(NETCONF_FAILURE_NONE), - _portError(0) +Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *uptr,const NetworkConfig *nconf) + : RR(renv) + , _uPtr(uptr) + , _id(nwid) + , _lastAnnouncedMulticastGroupsUpstream(0) + , _mac(renv->identity.address(),nwid) + , _portInitialized(false) + , _lastConfigUpdate(0) + , _destroyed(false) + , _netconfFailure(NETCONF_FAILURE_NONE) + , _portError(0) + , _multicast_groups_gauge{multicastGroupsFamily.Add({{"networkId", nwid_printf(_id).c_str()}})} { for(int i=0;i::iterator i(std::lower_bound(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg)); - if ( (i != _myMulticastGroups.end()) && (*i == mg) ) + if ( (i != _myMulticastGroups.end()) && (*i == mg) ) { _myMulticastGroups.erase(i); + _multicast_groups_gauge--; + } } uint64_t Network::handleConfigChunk(void *tPtr,const uint64_t packetId,const Address &source,const Buffer &chunk,unsigned int ptr) diff --git a/node/Network.hpp b/node/Network.hpp index 275e82f02..30ec03367 100644 --- a/node/Network.hpp +++ b/node/Network.hpp @@ -38,6 +38,8 @@ #include "NetworkConfig.hpp" #include "CertificateOfMembership.hpp" +#include + #define ZT_NETWORK_MAX_INCOMING_UPDATES 3 #define ZT_NETWORK_MAX_UPDATE_CHUNKS ((ZT_NETWORKCONFIG_DICT_CAPACITY / 1024) + 1) @@ -46,6 +48,9 @@ namespace ZeroTier { class RuntimeEnvironment; class Peer; + + + /** * A virtual LAN */ @@ -474,6 +479,8 @@ class Network Mutex _lock; AtomicCounter __refCount; + + prometheus::simpleapi::gauge_metric_t _multicast_groups_gauge; }; } // namespace ZeroTier