From d322f9312dda0603b0c3bddaa4e2e124990f524e Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Wed, 24 Jul 2019 18:48:33 +0200 Subject: [PATCH] auth: add metric for open TCP connections --- docs/performance.rst | 6 ++++++ pdns/common_startup.cc | 8 +++++++- pdns/tcpreceiver.cc | 8 ++++++++ pdns/tcpreceiver.hh | 2 ++ regression-tests.nobackend/counters/expected_result | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/performance.rst b/docs/performance.rst index e31ac892f7..850e352b9e 100644 --- a/docs/performance.rst +++ b/docs/performance.rst @@ -212,6 +212,12 @@ meta-cache-size ^^^^^^^^^^^^^^^ Number of entries in the metadata cache +.. _stat-open-tcp-connections: + +open-tcp-connections +~~~~~~~~~~~~~~~~~~~~ +Number of currently open TCP connections + .. _stat-overload-drops: overload-drops diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 63a0d094f5..fa56dd6870 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -247,6 +247,11 @@ static uint64_t getSysUserTimeMsec(const std::string& str) } +static uint64_t getTCPConnectionCount(const std::string& str) +{ + return TN->numTCPConnections(); +} + static uint64_t getQCount(const std::string& str) try { @@ -306,7 +311,8 @@ void declareStats(void) S.declare("tcp6-queries","Number of IPv6 TCP queries received"); S.declare("tcp6-answers","Number of IPv6 answers sent out over TCP"); - + + S.declare("open-tcp-connections","Number of currently open TCP connections", getTCPConnectionCount);; S.declare("qsize-q","Number of questions waiting for database attention", getQCount); diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index 0ea41bb88f..c925766966 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -68,6 +68,7 @@ extern StatBag S; pthread_mutex_t TCPNameserver::s_plock = PTHREAD_MUTEX_INITIALIZER; Semaphore *TCPNameserver::d_connectionroom_sem; +unsigned int TCPNameserver::d_maxTCPConnections = 0; PacketHandler *TCPNameserver::s_P; NetmaskGroup TCPNameserver::d_ng; size_t TCPNameserver::d_maxTransactionsPerConn; @@ -1195,6 +1196,7 @@ TCPNameserver::TCPNameserver() // sem_init(&d_connectionroom_sem,0,::arg().asNum("max-tcp-connections")); d_connectionroom_sem = new Semaphore( ::arg().asNum( "max-tcp-connections" )); + d_maxTCPConnections = ::arg().asNum( "max-tcp-connections" ); d_tid=0; vectorlocals; stringtok(locals,::arg()["local-address"]," ,"); @@ -1387,3 +1389,9 @@ void TCPNameserver::thread() } +unsigned int TCPNameserver::numTCPConnections() +{ + int room; + d_connectionroom_sem->getValue( &room); + return d_maxTCPConnections - room; +} diff --git a/pdns/tcpreceiver.hh b/pdns/tcpreceiver.hh index cfd6d30016..fd8b33c22f 100644 --- a/pdns/tcpreceiver.hh +++ b/pdns/tcpreceiver.hh @@ -47,6 +47,7 @@ public: TCPNameserver(); ~TCPNameserver(); void go(); + unsigned int numTCPConnections(); private: static void sendPacket(std::shared_ptr p, int outsock); @@ -65,6 +66,7 @@ private: static PacketHandler *s_P; pthread_t d_tid; static Semaphore *d_connectionroom_sem; + static unsigned int d_maxTCPConnections; static NetmaskGroup d_ng; static size_t d_maxTransactionsPerConn; static size_t d_maxConnectionsPerClient; diff --git a/regression-tests.nobackend/counters/expected_result b/regression-tests.nobackend/counters/expected_result index cf1ba2fd10..7e73f4fb65 100644 --- a/regression-tests.nobackend/counters/expected_result +++ b/regression-tests.nobackend/counters/expected_result @@ -11,6 +11,7 @@ dnsupdate-refused=0 incoming-notifications=0 key-cache-size=0 meta-cache-size=3 +open-tcp-connections=0 overload-drops=0 packetcache-size=4 qsize-q=0 -- 2.39.2