]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add metrics
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 28 Aug 2024 09:32:20 +0000 (11:32 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 30 Aug 2024 07:33:00 +0000 (09:33 +0200)
pdns/recursordist/RECURSOR-MIB.txt
pdns/recursordist/docs/metrics.rst
pdns/recursordist/rec-snmp.cc
pdns/recursordist/rec-tcounters.hh
pdns/recursordist/rec-tcp.cc
pdns/recursordist/rec_channel_rec.cc
pdns/recursordist/ws-recursor.cc
regression-tests.recursor-dnssec/test_SNMP.py

index ba743382ddfb9da81b438eef71e5f49e62d4d4a5..7103ead6ff4b12ee8ba547807b4ee4b465b26ed6 100644 (file)
@@ -66,6 +66,9 @@ rec MODULE-IDENTITY
     REVISION "202408130000Z"
     DESCRIPTION "Added metric for chain limits reached"
 
+    REVISION "202408280000Z"
+    DESCRIPTION "Added metric for too many incoming TCP connections"
+
     ::= { powerdns 2 }
 
 powerdns               OBJECT IDENTIFIER ::= { enterprises 43315 }
@@ -1280,6 +1283,14 @@ chainLimits OBJECT-TYPE
         "Chain limits reached"
     ::= { stats 151 }
 
+tcpOverflow OBJECT-TYPE
+    SYNTAX Counter64
+    MAX-ACCESS read-only
+    STATUS current
+    DESCRIPTION
+        "Incoming TCP limits reached"
+    ::= { stats 152 }
+
 ---
 --- Traps / Notifications
 ---
@@ -1478,7 +1489,8 @@ recGroup OBJECT-GROUP
         udrEvents,
         maxChainLength,
         maxChainWeight,
-        chainLimits
+        chainLimits,
+        tcpOverflow
     }
     STATUS current
     DESCRIPTION "Objects conformance group for PowerDNS Recursor"
index 8f1fef53db7f41645d4f4fb4ff9debf725d2f261..07811ce8ab23c6a04ba81963d2e228088e0d2767 100644 (file)
@@ -756,6 +756,12 @@ taskqueue-size
 
 number of tasks currently in the taskqueues
 
+.. _stat-tcp-overflow:
+
+tcp-overflow
+^^^^^^^^^^^^
+number of times an incoming TCP connection was closed immediately because there were too many open connections already
+
 .. _stat-tcp-client-overflow:
 
 tcp-client-overflow
index f6e91ec455d5d579472a55cf80350e6b1d5f3ea5..5825defd3018b40da828b15d491543c2b1577ff2 100644 (file)
@@ -206,6 +206,7 @@ static const oid10 udrEventsOID = {RECURSOR_STATS_OID, 148};
 static const oid10 maxChainLengthOID = {RECURSOR_STATS_OID, 149};
 static const oid10 maxChainWeightOID = {RECURSOR_STATS_OID, 150};
 static const oid10 chainLimitsOID = {RECURSOR_STATS_OID, 151};
+static const oid10 tcpOverflowOID = {RECURSOR_STATS_OID, 152};
 
 static std::unordered_map<oid, std::string> s_statsMap;
 
@@ -462,6 +463,7 @@ RecursorSNMPAgent::RecursorSNMPAgent(const std::string& name, const std::string&
   registerCounter64Stat("udr-events", udrEventsOID);
   registerCounter64Stat("max-chain-length", maxChainLengthOID);
   registerCounter64Stat("max-chain-weight", maxChainWeightOID);
+  registerCounter64Stat("tcp-overflow", tcpOverflowOID);
 
 #endif /* HAVE_NET_SNMP */
 }
index fdbce78d91cdd9689bf1462b6eb5a68db9c34a0a..a696c90b56c065a9b7c155e95eb78161eb56c745 100644 (file)
@@ -60,6 +60,7 @@ enum class Counter : uint8_t
   sourceDisallowedNotify, // when this is increased, qcounter is also
   zoneDisallowedNotify, // when this is increased, qcounter is also
   policyDrops,
+  tcpOverflow,
   tcpClientOverflow,
   clientParseError,
   serverParseError,
index 353550d292665ecf96d9ffce6fe3fb531fce497e..ef44a55a77b3a4a5b3ff66ca25c7b67f2cf3603c 100644 (file)
@@ -694,9 +694,12 @@ void handleNewTCPQuestion(int fileDesc, [[maybe_unused]] FDMultiplexer::funcpara
   if (newsock < 0) {
     return;
   }
-  auto closeSock = [newsock](const string& msg) {
+  auto closeSock = [newsock](rec::Counter cnt, const string& msg) {
     try {
       closesocket(newsock);
+      t_Counters.at(cnt)++;
+      // We want this bump to percolate up without too much delay
+      t_Counters.updateSnap(false);
     }
     catch (const PDNSException& e) {
       g_slogtcpin->error(Logr::Error, e.reason, msg, "exception", Logging::Loggable("PDNSException"));
@@ -704,13 +707,11 @@ void handleNewTCPQuestion(int fileDesc, [[maybe_unused]] FDMultiplexer::funcpara
   };
 
   if (TCPConnection::getCurrentConnections() >= g_maxTCPClients) {
-    t_Counters.at(rec::Counter::tcpClientOverflow)++;
-    closeSock("Error closing TCP socket after an overflow drop");
+    closeSock(rec::Counter::tcpOverflow, "Error closing TCP socket after an overflow drop");
     return;
   }
   if (g_multiTasker->numProcesses() >= g_maxMThreads) {
-    t_Counters.at(rec::Counter::overCapacityDrops)++;
-    closeSock("Error closing TCP socket after an over capacity drop");
+    closeSock(rec::Counter::overCapacityDrops, "Error closing TCP socket after an over capacity drop");
     return;
   }
 
@@ -733,14 +734,12 @@ void handleNewTCPQuestion(int fileDesc, [[maybe_unused]] FDMultiplexer::funcpara
       SLOG(g_log << Logger::Error << "[" << g_multiTasker->getTid() << "] dropping TCP query from " << mappedSource.toString() << ", address neither matched by allow-from nor proxy-protocol-from" << endl,
            g_slogtcpin->info(Logr::Error, "dropping TCP query address neither matched by allow-from nor proxy-protocol-from", "source", Logging::Loggable(mappedSource)));
     }
-    t_Counters.at(rec::Counter::unauthorizedTCP)++;
-    closeSock("Error closing TCP socket after an ACL drop");
+    closeSock(rec::Counter::unauthorizedTCP, "Error closing TCP socket after an ACL drop");
     return;
   }
 
   if (g_maxTCPPerClient > 0 && t_tcpClientCounts->count(addr) > 0 && (*t_tcpClientCounts)[addr] >= g_maxTCPPerClient) {
-    t_Counters.at(rec::Counter::tcpClientOverflow)++;
-    closeSock("Error closing TCP socket after a client overflow drop");
+    closeSock(rec::Counter::tcpClientOverflow, "Error closing TCP socket after a client overflow drop");
     return;
   }
 
index b46fed7684f97bc15ff696ce458a6259d19885fb..f4eb031a91f3d1d7cb691a729c8842fa3120666b 100644 (file)
@@ -1349,6 +1349,7 @@ static void registerAllStats1()
   addGetStat("unauthorized-tcp", [] { return g_Counters.sum(rec::Counter::unauthorizedTCP); });
   addGetStat("source-disallowed-notify", [] { return g_Counters.sum(rec::Counter::sourceDisallowedNotify); });
   addGetStat("zone-disallowed-notify", [] { return g_Counters.sum(rec::Counter::zoneDisallowedNotify); });
+  addGetStat("tcp-overflow", [] { return g_Counters.sum(rec::Counter::tcpOverflow); });
   addGetStat("tcp-client-overflow", [] { return g_Counters.sum(rec::Counter::tcpClientOverflow); });
 
   addGetStat("client-parse-errors", [] { return g_Counters.sum(rec::Counter::clientParseError); });
index c2a745ac2d8a3d9e4b2df31429937dba3a452111..54f4773ff4e5f05dc4a648c51bf217d638660617 100644 (file)
@@ -894,6 +894,9 @@ const std::map<std::string, MetricDefinition> MetricDefinitionStorage::d_metrics
   {"tcp-client-overflow",
    MetricDefinition(PrometheusMetricType::counter,
                     "Number of times an IP address was denied TCP access because it already had too many connections")},
+  {"tcp-overflow",
+   MetricDefinition(PrometheusMetricType::counter,
+                    "Number of times a TCP connection was denied access because too many connections")},
   {"tcp-clients",
    MetricDefinition(PrometheusMetricType::gauge,
                     "Number of currently active TCP/IP clients")},
index a3865195544bfc135d3d6857f6b5b0b1afc4a361..40907ad3aba14fa21e4c8cd8a52ba029feebeaea 100644 (file)
@@ -21,7 +21,7 @@ class SNMPTest(RecursorTest):
     """
 
     def _checkStatsValues(self, results):
-        count = 151
+        count = 152
         for i in list(range(1, count)):
             oid = self._snmpOID + '.1.' + str(i) + '.0'
             self.assertTrue(oid in results)