add metric for open tcp connections

This commit is contained in:
Grant Limberg 2024-05-08 12:36:57 -07:00
parent 59b2f73541
commit b71e7bd0ab
No known key found for this signature in database
GPG Key ID: 8F2F97D3BE8D7735
3 changed files with 7 additions and 0 deletions

View File

@ -3,6 +3,9 @@
namespace ZeroTier { namespace ZeroTier {
namespace Metrics { namespace Metrics {
prometheus::simpleapi::gauge_metric_t tcp_connections
{"tcp_connections", "TCP connections"};
prometheus::simpleapi::counter_metric_t udp_open_failed prometheus::simpleapi::counter_metric_t udp_open_failed
{"udp_open_failed", "UDP open failed"}; {"udp_open_failed", "UDP open failed"};

View File

@ -5,6 +5,8 @@
namespace ZeroTier { namespace ZeroTier {
namespace Metrics { namespace Metrics {
extern prometheus::simpleapi::gauge_metric_t tcp_connections;
extern prometheus::simpleapi::counter_metric_t udp_open_failed; extern prometheus::simpleapi::counter_metric_t udp_open_failed;
extern prometheus::simpleapi::counter_metric_t tcp_opened; extern prometheus::simpleapi::counter_metric_t tcp_opened;

View File

@ -191,6 +191,7 @@ struct TcpProxyService
*uptrN = (void *)&c; *uptrN = (void *)&c;
printf("<< TCP from %s -> %.16llx\n",inet_ntoa(reinterpret_cast<const struct sockaddr_in *>(from)->sin_addr),(unsigned long long)&c); printf("<< TCP from %s -> %.16llx\n",inet_ntoa(reinterpret_cast<const struct sockaddr_in *>(from)->sin_addr),(unsigned long long)&c);
Metrics::tcp_opened++; Metrics::tcp_opened++;
Metrics::tcp_connections++;
} }
void phyOnTcpClose(PhySocket *sock,void **uptr) void phyOnTcpClose(PhySocket *sock,void **uptr)
@ -293,6 +294,7 @@ struct TcpProxyService
for(std::vector<PhySocket *>::iterator s(toClose.begin());s!=toClose.end();++s) { for(std::vector<PhySocket *>::iterator s(toClose.begin());s!=toClose.end();++s) {
phy->close(*s); phy->close(*s);
Metrics::tcp_closed++; Metrics::tcp_closed++;
Metrics::tcp_connections--;
} }
} }
}; };