Skip to content

Commit

Permalink
testing out a labled gauge on Networks
Browse files Browse the repository at this point in the history
  • Loading branch information
glimberg committed Apr 20, 2023
1 parent bd8f048 commit 499ed6d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
37 changes: 25 additions & 12 deletions node/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZT_NETWORK_MAX_INCOMING_UPDATES;++i)
_incomingConfigChunks[i].ts = 0;
Expand Down Expand Up @@ -852,15 +862,18 @@ void Network::multicastSubscribe(void *tPtr,const MulticastGroup &mg)
if (!std::binary_search(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg)) {
_myMulticastGroups.insert(std::upper_bound(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg),mg);
_sendUpdatesToMembers(tPtr,&mg);
_multicast_groups_gauge++;
}
}

void Network::multicastUnsubscribe(const MulticastGroup &mg)
{
Mutex::Lock _l(_lock);
std::vector<MulticastGroup>::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<ZT_PROTO_MAX_PACKET_LENGTH> &chunk,unsigned int ptr)
Expand Down
7 changes: 7 additions & 0 deletions node/Network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "NetworkConfig.hpp"
#include "CertificateOfMembership.hpp"

#include <prometheus/simpleapi.h>

#define ZT_NETWORK_MAX_INCOMING_UPDATES 3
#define ZT_NETWORK_MAX_UPDATE_CHUNKS ((ZT_NETWORKCONFIG_DICT_CAPACITY / 1024) + 1)

Expand All @@ -46,6 +48,9 @@ namespace ZeroTier {
class RuntimeEnvironment;
class Peer;




/**
* A virtual LAN
*/
Expand Down Expand Up @@ -474,6 +479,8 @@ class Network
Mutex _lock;

AtomicCounter __refCount;

prometheus::simpleapi::gauge_metric_t _multicast_groups_gauge;
};

} // namespace ZeroTier
Expand Down

0 comments on commit 499ed6d

Please sign in to comment.