Skip to content

Commit

Permalink
add metric for open tcp connections
Browse files Browse the repository at this point in the history
  • Loading branch information
glimberg committed May 8, 2024
1 parent 59b2f73 commit b71e7bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tcp-proxy/Metrics.cpp
Expand Up @@ -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"};

Expand Down
2 changes: 2 additions & 0 deletions tcp-proxy/Metrics.hpp
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tcp-proxy/tcp-proxy.cpp
Expand Up @@ -191,6 +191,7 @@ struct TcpProxyService
*uptrN = (void *)&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_connections++;
}

void phyOnTcpClose(PhySocket *sock,void **uptr)
Expand Down Expand Up @@ -293,6 +294,7 @@ struct TcpProxyService
for(std::vector<PhySocket *>::iterator s(toClose.begin());s!=toClose.end();++s) {
phy->close(*s);
Metrics::tcp_closed++;
Metrics::tcp_connections--;
}
}
};
Expand Down

0 comments on commit b71e7bd

Please sign in to comment.