From: Remi Gacogne Date: Wed, 17 Mar 2021 10:19:27 +0000 (+0100) Subject: dnsdist: Add a metric for TCP listen queue full events X-Git-Tag: rec-4.5.0-beta1~15^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e150c22cfca32f6ea44d70ae5eb2e68de12b0dc9;p=thirdparty%2Fpdns.git dnsdist: Add a metric for TCP listen queue full events --- diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index eec18b2022..096b5cabf8 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -152,6 +152,7 @@ const std::map MetricDefinitionStorage::metrics{ { "udp-noport-errors", MetricDefinition(PrometheusMetricType::counter, "From /proc/net/snmp NoPorts") }, { "udp-recvbuf-errors", MetricDefinition(PrometheusMetricType::counter, "From /proc/net/snmp RcvbufErrors") }, { "udp-sndbuf-errors", MetricDefinition(PrometheusMetricType::counter, "From /proc/net/snmp SndbufErrors") }, + { "tcp-listen-overflows", MetricDefinition(PrometheusMetricType::counter, "From /proc/net/netstat ListenOverflows") }, { "proxy-protocol-invalid", MetricDefinition(PrometheusMetricType::counter, "Number of queries dropped because of an invalid Proxy Protocol header") }, }; diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 0c00d2c831..e101d0815b 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -369,6 +369,7 @@ struct DNSDistStats {"udp-noport-errors", boost::bind(udpErrorStats, "udp-noport-errors")}, {"udp-recvbuf-errors", boost::bind(udpErrorStats, "udp-recvbuf-errors")}, {"udp-sndbuf-errors", boost::bind(udpErrorStats, "udp-sndbuf-errors")}, + {"tcp-listen-overflows", std::bind(tcpErrorStats, "ListenOverflows")}, {"noncompliant-queries", &nonCompliantQueries}, {"noncompliant-responses", &nonCompliantResponses}, {"proxy-protocol-invalid", &proxyProtocolInvalid}, diff --git a/pdns/dnsdistdist/docs/statistics.rst b/pdns/dnsdistdist/docs/statistics.rst index b1246e47c0..194fdc8ce4 100644 --- a/pdns/dnsdistdist/docs/statistics.rst +++ b/pdns/dnsdistdist/docs/statistics.rst @@ -227,6 +227,12 @@ servfail-responses ------------------ Number of servfail answers received from backends. +tcp-listen-overflows +-------------------- +.. versionadded:: 1.6.0 + +From /proc/net/netstat ListenOverflows. + trunc-failures -------------- Number of errors encountered while truncating an answer. diff --git a/pdns/misc.cc b/pdns/misc.cc index de9e003eb9..cd8725e8a0 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1147,6 +1147,31 @@ uint64_t udpErrorStats(const std::string& str) return 0; } +uint64_t tcpErrorStats(const std::string& str) +{ +#ifdef __linux__ + ifstream ifs("/proc/net/netstat"); + if (!ifs) { + return 0; + } + + string line; + vector parts; + while (getline(ifs,line)) { + if (line.size() > 9 && boost::starts_with(line, "TcpExt: ") && isdigit(line.at(8))) { + stringtok(parts, line, " \n\t\r"); + + if (parts.size() < 21) { + break; + } + + return std::stoull(parts.at(20)); + } + } +#endif + return 0; +} + uint64_t getCPUIOWait(const std::string& str) { #ifdef __linux__ diff --git a/pdns/misc.hh b/pdns/misc.hh index 3ee14f8ad7..83ca2178dd 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -561,6 +561,7 @@ size_t getPipeBufferSize(int fd); bool setPipeBufferSize(int fd, size_t size); uint64_t udpErrorStats(const std::string& str); +uint64_t tcpErrorStats(const std::string& str); uint64_t getRealMemoryUsage(const std::string&); uint64_t getSpecialMemoryUsage(const std::string&); uint64_t getOpenFileDescriptors(const std::string&); diff --git a/regression-tests.dnsdist/test_API.py b/regression-tests.dnsdist/test_API.py index 461dc554f6..90693dacf1 100644 --- a/regression-tests.dnsdist/test_API.py +++ b/regression-tests.dnsdist/test_API.py @@ -240,7 +240,7 @@ class TestAPIBasics(DNSDistTest): 'cache-misses', 'cpu-iowait', 'cpu-steal', 'cpu-sys-msec', 'cpu-user-msec', 'fd-usage', 'dyn-blocked', 'dyn-block-nmg-size', 'rule-servfail', 'rule-truncated', 'security-status', 'udp-in-errors', 'udp-noport-errors', 'udp-recvbuf-errors', 'udp-sndbuf-errors', - 'doh-query-pipe-full', 'doh-response-pipe-full', 'proxy-protocol-invalid'] + 'doh-query-pipe-full', 'doh-response-pipe-full', 'proxy-protocol-invalid', 'tcp-listen-overflows'] for key in expected: self.assertIn(key, values)