mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Add metrics for sent/received bytes (total)
This commit is contained in:
parent
1ca814d166
commit
5657406fd4
4 changed files with 35 additions and 5 deletions
|
@ -22,6 +22,16 @@ namespace prometheus {
|
|||
|
||||
namespace ZeroTier {
|
||||
namespace Metrics {
|
||||
// Data Sent/Received Metrics
|
||||
prometheus::simpleapi::counter_metric_t udp_send
|
||||
{ "zt_udp_data_sent", "number of bytes ZeroTier has sent via UDP" };
|
||||
prometheus::simpleapi::counter_metric_t udp_recv
|
||||
{ "zt_udp_data_recv", "number of bytes ZeroTier has received via UDP" };
|
||||
prometheus::simpleapi::counter_metric_t tcp_send
|
||||
{ "zt_tcp_data_sent", "number of bytes ZeroTier has sent via TCP" };
|
||||
prometheus::simpleapi::counter_metric_t tcp_recv
|
||||
{ "zt_tcp_data_recv", "number of bytes ZeroTier has received via TCP" };
|
||||
|
||||
// General Controller Metrics
|
||||
prometheus::simpleapi::gauge_metric_t network_count
|
||||
{"controller_network_count", "number of networks the controller is serving"};
|
||||
|
|
|
@ -22,6 +22,12 @@ namespace prometheus {
|
|||
|
||||
namespace ZeroTier {
|
||||
namespace Metrics {
|
||||
// Data Sent/Received Metrics
|
||||
extern prometheus::simpleapi::counter_metric_t udp_send;
|
||||
extern prometheus::simpleapi::counter_metric_t udp_recv;
|
||||
extern prometheus::simpleapi::counter_metric_t tcp_send;
|
||||
extern prometheus::simpleapi::counter_metric_t tcp_recv;
|
||||
|
||||
// General Controller Metrics
|
||||
extern prometheus::simpleapi::gauge_metric_t network_count;
|
||||
extern prometheus::simpleapi::gauge_metric_t member_count;
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include "../node/Metrics.hpp"
|
||||
|
||||
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
|
||||
#ifndef IPV6_DONTFRAG
|
||||
#define IPV6_DONTFRAG 62
|
||||
|
@ -452,9 +454,13 @@ public:
|
|||
{
|
||||
PhySocketImpl &sws = *(reinterpret_cast<PhySocketImpl *>(sock));
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
return ((long)::sendto(sws.sock,reinterpret_cast<const char *>(data),len,0,remoteAddress,(remoteAddress->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) == (long)len);
|
||||
ssize_t sent = ((long)::sendto(sws.sock,reinterpret_cast<const char *>(data),len,0,remoteAddress,(remoteAddress->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) == (long)len);
|
||||
Metrics::udp_send += sent;
|
||||
return sent;
|
||||
#else
|
||||
return ((long)::sendto(sws.sock,data,len,0,remoteAddress,(remoteAddress->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) == (long)len);
|
||||
ssize_t sent = ((long)::sendto(sws.sock,data,len,0,remoteAddress,(remoteAddress->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) == (long)len);
|
||||
Metrics::udp_send += sent;
|
||||
return sent;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -2470,9 +2470,11 @@ public:
|
|||
if (_forceTcpRelay) {
|
||||
return;
|
||||
}
|
||||
Metrics::udp_recv += len;
|
||||
const uint64_t now = OSUtils::now();
|
||||
if ((len >= 16)&&(reinterpret_cast<const InetAddress *>(from)->ipScope() == InetAddress::IP_SCOPE_GLOBAL))
|
||||
if ((len >= 16)&&(reinterpret_cast<const InetAddress *>(from)->ipScope() == InetAddress::IP_SCOPE_GLOBAL)) {
|
||||
_lastDirectReceiveFromGlobal = now;
|
||||
}
|
||||
const ZT_ResultCode rc = _node->processWirePacket(nullptr,now,reinterpret_cast<int64_t>(sock),reinterpret_cast<const struct sockaddr_storage *>(from),data,len,&_nextBackgroundTaskDeadline);
|
||||
if (ZT_ResultCode_isFatal(rc)) {
|
||||
char tmp[256];
|
||||
|
@ -2559,6 +2561,7 @@ public:
|
|||
{
|
||||
try {
|
||||
if (!len) return; // sanity check, should never happen
|
||||
Metrics::tcp_recv += len;
|
||||
TcpConnection *tc = reinterpret_cast<TcpConnection *>(*uptr);
|
||||
tc->lastReceive = OSUtils::now();
|
||||
switch(tc->type) {
|
||||
|
@ -2697,6 +2700,7 @@ public:
|
|||
Mutex::Lock _l(tc->writeq_m);
|
||||
if (tc->writeq.length() > 0) {
|
||||
long sent = (long)_phy.streamSend(sock,tc->writeq.data(),(unsigned long)tc->writeq.length(),true);
|
||||
Metrics::tcp_send += sent;
|
||||
if (sent > 0) {
|
||||
if ((unsigned long)sent >= (unsigned long)tc->writeq.length()) {
|
||||
tc->writeq.clear();
|
||||
|
@ -3235,9 +3239,13 @@ public:
|
|||
// working we can instantly "fail forward" to it and stop using TCP
|
||||
// proxy fallback, which is slow.
|
||||
if ((localSocket != -1)&&(localSocket != 0)&&(_binder.isUdpSocketValid((PhySocket *)((uintptr_t)localSocket)))) {
|
||||
if ((ttl)&&(addr->ss_family == AF_INET)) _phy.setIp4UdpTtl((PhySocket *)((uintptr_t)localSocket),ttl);
|
||||
if ((ttl)&&(addr->ss_family == AF_INET)) {
|
||||
_phy.setIp4UdpTtl((PhySocket *)((uintptr_t)localSocket),ttl);
|
||||
}
|
||||
const bool r = _phy.udpSend((PhySocket *)((uintptr_t)localSocket),(const struct sockaddr *)addr,data,len);
|
||||
if ((ttl)&&(addr->ss_family == AF_INET)) _phy.setIp4UdpTtl((PhySocket *)((uintptr_t)localSocket),255);
|
||||
if ((ttl)&&(addr->ss_family == AF_INET)) {
|
||||
_phy.setIp4UdpTtl((PhySocket *)((uintptr_t)localSocket),255);
|
||||
}
|
||||
return ((r) ? 0 : -1);
|
||||
} else {
|
||||
return ((_binder.udpSendAll(_phy,addr,data,len,ttl)) ? 0 : -1);
|
||||
|
|
Loading…
Add table
Reference in a new issue