From f8e4116582109583924d64823dcb83b8d2e99457 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Mon, 1 May 2023 15:12:55 -0700 Subject: [PATCH] Found more places for packet metrics --- node/Bond.cpp | 1 + node/IncomingPacket.cpp | 14 ++++++++++++++ node/Membership.cpp | 1 + node/Metrics.cpp | 1 + node/Metrics.hpp | 2 +- node/Multicaster.cpp | 2 ++ node/Peer.cpp | 10 ++++++++++ node/Peer.hpp | 5 +++-- node/Switch.cpp | 1 + 9 files changed, 34 insertions(+), 3 deletions(-) diff --git a/node/Bond.cpp b/node/Bond.cpp index 3ae3f98ae..09c64757d 100644 --- a/node/Bond.cpp +++ b/node/Bond.cpp @@ -857,6 +857,7 @@ void Bond::sendQOS_MEASUREMENT(void* tPtr, int pathIdx, int64_t localSocket, con else { RR->sw->send(tPtr, outp, false); } + Metrics::pkt_qos_out++; _paths[pathIdx].packetsReceivedSinceLastQoS = 0; _paths[pathIdx].lastQoSMeasurement = now; _overheadBytes += outp.size(); diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index 532a99fe0..a0cb1b135 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -366,6 +366,8 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR,void *tPtr,const bool outp.append((uint64_t)pid); outp.append((uint8_t)Packet::ERROR_IDENTITY_COLLISION); outp.armor(key,true,peer->aesKeysIfSupported()); + Metrics::pkt_error_out++; + Metrics::pkt_error_identity_collision_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); } else { RR->t->incomingPacketMessageAuthenticationFailure(tPtr,_path,pid,fromAddress,hops(),"invalid MAC"); @@ -517,6 +519,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR,void *tPtr,const bool outp.armor(peer->key(),true,peer->aesKeysIfSupported()); peer->recordOutgoingPacket(_path,outp.packetId(),outp.payloadLength(),outp.verb(),ZT_QOS_NO_FLOW,now); + Metrics::pkt_ok_out++; _path->send(RR,tPtr,outp.data(),outp.size(),now); peer->setRemoteVersion(protoVersion,vMajor,vMinor,vRevision); // important for this to go first so received() knows the version @@ -668,7 +671,9 @@ bool IncomingPacket::_doWHOIS(const RuntimeEnvironment *RR,void *tPtr,const Shar } if (count > 0) { + Metrics::pkt_ok_out++; outp.armor(peer->key(),true,peer->aesKeysIfSupported()); + Metrics::pkt_ok_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); } @@ -896,6 +901,7 @@ bool IncomingPacket::_doEXT_FRAME(const RuntimeEnvironment *RR,void *tPtr,const const int64_t now = RR->node->now(); outp.armor(peer->key(),true,peer->aesKeysIfSupported()); peer->recordOutgoingPacket(_path,outp.packetId(),outp.payloadLength(),outp.verb(),ZT_QOS_NO_FLOW,now); + Metrics::pkt_ok_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); } @@ -923,6 +929,7 @@ bool IncomingPacket::_doECHO(const RuntimeEnvironment *RR,void *tPtr,const Share outp.append(reinterpret_cast(data()) + ZT_PACKET_IDX_PAYLOAD,size() - ZT_PACKET_IDX_PAYLOAD); outp.armor(peer->key(),true,peer->aesKeysIfSupported()); peer->recordOutgoingPacket(_path,outp.packetId(),outp.payloadLength(),outp.verb(),ZT_QOS_NO_FLOW,now); + Metrics::pkt_ok_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); peer->received(tPtr,_path,hops(),pid,payloadLength(),Packet::VERB_ECHO,0,Packet::VERB_NOP,false,0,ZT_QOS_NO_FLOW); @@ -1100,6 +1107,8 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,void outp.append((unsigned char)Packet::ERROR_UNSUPPORTED_OPERATION); outp.append(nwid); outp.armor(peer->key(),true,peer->aesKeysIfSupported()); + Metrics::pkt_error_out++; + Metrics::pkt_error_unsupported_op_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); } @@ -1123,6 +1132,7 @@ bool IncomingPacket::_doNETWORK_CONFIG(const RuntimeEnvironment *RR,void *tPtr,c const int64_t now = RR->node->now(); outp.armor(peer->key(),true,peer->aesKeysIfSupported()); peer->recordOutgoingPacket(_path,outp.packetId(),outp.payloadLength(),outp.verb(),ZT_QOS_NO_FLOW,now); + Metrics::pkt_ok_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); } } @@ -1164,6 +1174,7 @@ bool IncomingPacket::_doMULTICAST_GATHER(const RuntimeEnvironment *RR,void *tPtr if (gatheredLocally > 0) { outp.armor(peer->key(),true,peer->aesKeysIfSupported()); peer->recordOutgoingPacket(_path,outp.packetId(),outp.payloadLength(),outp.verb(),ZT_QOS_NO_FLOW,now); + Metrics::pkt_ok_out++; _path->send(RR,tPtr,outp.data(),outp.size(),now); } } @@ -1264,6 +1275,7 @@ bool IncomingPacket::_doMULTICAST_FRAME(const RuntimeEnvironment *RR,void *tPtr, const int64_t now = RR->node->now(); outp.armor(peer->key(),true,peer->aesKeysIfSupported()); peer->recordOutgoingPacket(_path,outp.packetId(),outp.payloadLength(),outp.verb(),ZT_QOS_NO_FLOW,now); + Metrics::pkt_ok_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); } } @@ -1406,6 +1418,8 @@ void IncomingPacket::_sendErrorNeedCredentials(const RuntimeEnvironment *RR,void outp.append((uint8_t)Packet::ERROR_NEED_MEMBERSHIP_CERTIFICATE); outp.append(nwid); outp.armor(peer->key(),true,peer->aesKeysIfSupported()); + Metrics::pkt_error_out++; + Metrics::pkt_error_need_membership_cert_out++; _path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now()); } diff --git a/node/Membership.cpp b/node/Membership.cpp index 8ddd61f09..b8efab869 100644 --- a/node/Membership.cpp +++ b/node/Membership.cpp @@ -97,6 +97,7 @@ void Membership::pushCredentials(const RuntimeEnvironment *RR,void *tPtr,const i outp.compress(); RR->sw->send(tPtr,outp,true); + Metrics::pkt_network_credentials_out++; } _lastPushedCredentials = now; diff --git a/node/Metrics.cpp b/node/Metrics.cpp index d57bb2d00..c90331982 100644 --- a/node/Metrics.cpp +++ b/node/Metrics.cpp @@ -11,6 +11,7 @@ */ #include +#include namespace prometheus { namespace simpleapi { diff --git a/node/Metrics.hpp b/node/Metrics.hpp index f38bab6b9..7530e48c0 100644 --- a/node/Metrics.hpp +++ b/node/Metrics.hpp @@ -13,6 +13,7 @@ #define METRICS_H_ #include +#include namespace prometheus { namespace simpleapi { @@ -94,7 +95,6 @@ namespace ZeroTier { extern prometheus::simpleapi::counter_metric_t pkt_error_authentication_required_out; extern prometheus::simpleapi::counter_metric_t pkt_error_internal_server_error_out; - // Data Sent/Received Metrics extern prometheus::simpleapi::counter_metric_t udp_send; extern prometheus::simpleapi::counter_metric_t udp_recv; diff --git a/node/Multicaster.cpp b/node/Multicaster.cpp index d93b2ae10..b40835054 100644 --- a/node/Multicaster.cpp +++ b/node/Multicaster.cpp @@ -195,6 +195,7 @@ void Multicaster::send( outp.append(data,len); if (!network->config().disableCompression()) outp.compress(); outp.armor(bestMulticastReplicator->key(),true,bestMulticastReplicator->aesKeysIfSupported()); + Metrics::pkt_multicast_frame_out++; bestMulticastReplicatorPath->send(RR,tPtr,outp.data(),outp.size(),now); return; } @@ -321,6 +322,7 @@ void Multicaster::send( com->serialize(outp); RR->node->expectReplyTo(outp.packetId()); RR->sw->send(tPtr,outp,true); + Metrics::pkt_multicast_gather_out++; } } diff --git a/node/Peer.cpp b/node/Peer.cpp index 3972204c0..eae01b807 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -28,6 +28,11 @@ 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), @@ -238,6 +243,7 @@ void Peer::received( outp->setAt(ZT_PACKET_IDX_PAYLOAD,(uint16_t)count); outp->compress(); outp->armor(_key,true,aesKeysIfSupported()); + Metrics::pkt_push_direct_paths_out++; path->send(RR,tPtr,outp->data(),outp->size(),now); } delete outp; @@ -377,6 +383,7 @@ void Peer::introduce(void *const tPtr,const int64_t now,const SharedPtr &o outp.append(other->_paths[theirs].p->address().rawIpData(),4); } outp.armor(_key,true,aesKeysIfSupported()); + Metrics::pkt_rendezvous_out++; _paths[mine].p->send(RR,tPtr,outp.data(),outp.size(),now); } else { Packet outp(other->_id.address(),RR->identity.address(),Packet::VERB_RENDEZVOUS); @@ -391,6 +398,7 @@ void Peer::introduce(void *const tPtr,const int64_t now,const SharedPtr &o outp.append(_paths[mine].p->address().rawIpData(),4); } outp.armor(other->_key,true,other->aesKeysIfSupported()); + Metrics::pkt_rendezvous_out++; other->_paths[theirs].p->send(RR,tPtr,outp.data(),outp.size(),now); } ++alt; @@ -433,6 +441,7 @@ void Peer::sendHELLO(void *tPtr,const int64_t localSocket,const InetAddress &atA if (atAddress) { outp.armor(_key,false,nullptr); // false == don't encrypt full payload, but add MAC + Metrics::pkt_hello_out++; RR->node->expectReplyTo(outp.packetId()); RR->node->putPacket(tPtr,RR->node->lowBandwidthModeEnabled() ? localSocket : -1,atAddress,outp.data(),outp.size()); } else { @@ -446,6 +455,7 @@ void Peer::attemptToContactAt(void *tPtr,const int64_t localSocket,const InetAdd if ( (!sendFullHello) && (_vProto >= 5) && (!((_vMajor == 1)&&(_vMinor == 1)&&(_vRevision == 0))) ) { Packet outp(_id.address(),RR->identity.address(),Packet::VERB_ECHO); outp.armor(_key,true,aesKeysIfSupported()); + Metrics::pkt_echo_out++; RR->node->expectReplyTo(outp.packetId()); RR->node->putPacket(tPtr,localSocket,atAddress,outp.data(),outp.size()); } else { diff --git a/node/Peer.hpp b/node/Peer.hpp index e6e9b65ed..40ac7bbf4 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -34,6 +34,7 @@ #include "Mutex.hpp" #include "Bond.hpp" #include "AES.hpp" +#include "Metrics.hpp" #define ZT_PEER_MAX_SERIALIZED_STATE_SIZE (sizeof(Peer) + 32 + (sizeof(Path) * 2)) @@ -50,7 +51,7 @@ class Peer friend class Bond; private: - Peer() {} // disabled to prevent bugs -- should not be constructed uninitialized + Peer() = delete; // disabled to prevent bugs -- should not be constructed uninitialized public: ~Peer() { @@ -314,7 +315,7 @@ public: } else { SharedPtr bp(getAppropriatePath(now,false)); if (bp) { - return bp->latency(); + return (unsigned int)bp->latency(); } return 0xffff; } diff --git a/node/Switch.cpp b/node/Switch.cpp index 7b1d47ac9..4e88e2da5 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -98,6 +98,7 @@ void Switch::onRemotePacket(void *tPtr,const int64_t localSocket,const InetAddre _lastBeaconResponse = now; Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NOP); outp.armor(peer->key(),true,peer->aesKeysIfSupported()); + Metrics::pkt_nop_out++; path->send(RR,tPtr,outp.data(),outp.size(),now); } }