From b71e7bd0ab3d07b7ab5f778326c25deeb08a3cf9 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 8 May 2024 12:36:57 -0700 Subject: [PATCH] add metric for open tcp connections --- tcp-proxy/Metrics.cpp | 3 +++ tcp-proxy/Metrics.hpp | 2 ++ tcp-proxy/tcp-proxy.cpp | 2 ++ 3 files changed, 7 insertions(+) diff --git a/tcp-proxy/Metrics.cpp b/tcp-proxy/Metrics.cpp index e6cc68f1e..db14f3a78 100644 --- a/tcp-proxy/Metrics.cpp +++ b/tcp-proxy/Metrics.cpp @@ -3,6 +3,9 @@ namespace ZeroTier { namespace Metrics { + prometheus::simpleapi::gauge_metric_t tcp_connections + {"tcp_connections", "TCP connections"}; + prometheus::simpleapi::counter_metric_t udp_open_failed {"udp_open_failed", "UDP open failed"}; diff --git a/tcp-proxy/Metrics.hpp b/tcp-proxy/Metrics.hpp index 4211c9b89..1ffe891a9 100644 --- a/tcp-proxy/Metrics.hpp +++ b/tcp-proxy/Metrics.hpp @@ -5,6 +5,8 @@ namespace ZeroTier { 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 tcp_opened; diff --git a/tcp-proxy/tcp-proxy.cpp b/tcp-proxy/tcp-proxy.cpp index a659ccc45..f770a42fe 100644 --- a/tcp-proxy/tcp-proxy.cpp +++ b/tcp-proxy/tcp-proxy.cpp @@ -191,6 +191,7 @@ struct TcpProxyService *uptrN = (void *)&c; printf("<< TCP from %s -> %.16llx\n",inet_ntoa(reinterpret_cast(from)->sin_addr),(unsigned long long)&c); Metrics::tcp_opened++; + Metrics::tcp_connections++; } void phyOnTcpClose(PhySocket *sock,void **uptr) @@ -293,6 +294,7 @@ struct TcpProxyService for(std::vector::iterator s(toClose.begin());s!=toClose.end();++s) { phy->close(*s); Metrics::tcp_closed++; + Metrics::tcp_connections--; } } };