]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Prometheus stats plus tweaks in rec_control
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 31 Aug 2022 06:43:38 +0000 (08:43 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 28 Sep 2022 09:30:32 +0000 (11:30 +0200)
pdns/rec_channel_rec.cc
pdns/recursordist/docs/manpages/rec_control.1.rst
pdns/ws-recursor.cc

index 8722a5551cf3ea84c602018eefe11b34cf87f0dd..942a2b9dfe9b3acb06249eefd98a14ab84197bf1 100644 (file)
@@ -941,14 +941,14 @@ static ProxyMappingStats_t* pleaseGetProxyMappingStats()
 
 static RemoteLoggerStats_t* pleaseGetRemoteLoggerStats()
 {
-  auto ret = new RemoteLoggerStats_t;
+  auto ret = make_unique<RemoteLoggerStats_t>();
 
   if (t_protobufServers) {
     for (const auto& s : *t_protobufServers) {
       ret->emplace(std::make_pair(s->address(), s->getStats()));
     }
   }
-  return ret;
+  return ret.release();
 }
 
 static string doGetProxyMappingStats()
@@ -964,52 +964,52 @@ static string doGetProxyMappingStats()
 
 static RemoteLoggerStats_t* pleaseGetOutgoingRemoteLoggerStats()
 {
-  auto ret = new RemoteLoggerStats_t;
+  auto ret = make_unique<RemoteLoggerStats_t>();
 
   if (t_outgoingProtobufServers) {
     for (const auto& s : *t_outgoingProtobufServers) {
       ret->emplace(std::make_pair(s->address(), s->getStats()));
     }
   }
-  return ret;
+  return ret.release();
 }
 
 #ifdef HAVE_FSTRM
 static RemoteLoggerStats_t* pleaseGetFramestreamLoggerStats()
 {
-  auto ret = new RemoteLoggerStats_t;
+  auto ret = make_unique<RemoteLoggerStats_t>();
 
   if (t_frameStreamServersInfo.servers) {
     for (const auto& s : *t_frameStreamServersInfo.servers) {
       ret->emplace(std::make_pair(s->address(), s->getStats()));
     }
   }
-  return ret;
+  return ret.release();
 }
 #endif
 
-static void remoteLoggerStats(const string& name, const RemoteLoggerStats_t& stats, ostringstream& os)
+static void remoteLoggerStats(const string& type, const RemoteLoggerStats_t& stats, ostringstream& os)
 {
-  if (stats.size() > 0) {
-    std::string filler(name.size(), ' ');
-    os << name << "\tQueued\tPipe-\tToo-\tOther-\tAddress" << endl;
-    os << filler << "\t\tFull\tLarge\terror" << endl;
-    for (const auto& [key, entry]: stats) {
-      os << filler<< '\t' << entry.d_queued << '\t' << entry.d_pipeFull << '\t' << entry.d_tooLarge << '\t' << entry.d_otherError << '\t' << key << endl;
-    }
+  if (stats.empty()) {
+    return;
+  }
+  for (const auto& [key, entry]: stats) {
+    os << entry.d_queued << '\t' << entry.d_pipeFull << '\t' << entry.d_tooLarge << '\t' << entry.d_otherError << '\t' << key << '\t' << type << endl;
   }
 }
 
 static string getRemoteLoggerStats()
 {
   ostringstream os;
+  os << "Queued\tPipe-\tToo-\tOther-\tAddress\tType" << endl;
+  os << "\tFull\tLarge\terror" << endl;
   auto stats = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetRemoteLoggerStats);
-  remoteLoggerStats("Protobuf   ", stats, os);
+  remoteLoggerStats("protobuf", stats, os);
   stats = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetOutgoingRemoteLoggerStats);
-  remoteLoggerStats("OutProtobuf", stats, os);
+  remoteLoggerStats("outgoingProtobuf", stats, os);
 #ifdef HAVE_FSTRM
   stats = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetFramestreamLoggerStats);
-  remoteLoggerStats("Framestream", stats, os);
+  remoteLoggerStats("dnstapFrameStream", stats, os);
 #endif
   return os.str();
 }
@@ -1259,6 +1259,36 @@ static StatsMap toProxyMappingStatsMap(const string& name)
   return entries;
 }
 
+static StatsMap toRemoteLoggerStatsMap(const string& name)
+{
+  const auto pbasename = getPrometheusName(name);
+  StatsMap entries;
+
+  auto stats1 = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetRemoteLoggerStats);
+  auto stats2 = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetOutgoingRemoteLoggerStats);
+  auto stats3 = broadcastAccFunction<RemoteLoggerStats_t>(pleaseGetFramestreamLoggerStats);
+  uint64_t count = 0;
+  for (const auto& [stats, type] : { make_pair(stats1, "protobuf") , make_pair(stats2, "outgoingProtobuf"), make_pair(stats3, "dnstapFrameStream") } ) {
+    for (const auto& [key, entry] : stats) {
+      auto keyname = pbasename + "{address=\"" + key + "\",type=\"" + type + "\",count=\"";
+      auto sname1 = name + "-q-" + std::to_string(count);
+      auto pname1 = keyname + "queued\"}";
+      entries.emplace(sname1, StatsMapEntry{pname1, std::to_string(entry.d_queued)});
+      auto sname2 = name + "-p-" + std::to_string(count);
+      auto pname2 = keyname + "pipeFull\"}";
+      entries.emplace(sname2, StatsMapEntry{pname2, std::to_string(entry.d_pipeFull)});
+      auto sname3 = name + "-t-" + std::to_string(count);
+      auto pname3 = keyname + "tooLarge\"}";
+      entries.emplace(sname3, StatsMapEntry{pname3, std::to_string(entry.d_tooLarge)});
+      auto sname4 = name + "-o-" + std::to_string(count);
+      auto pname4 = keyname + "otherError\"}";
+      entries.emplace(sname4, StatsMapEntry{pname4, std::to_string(entry.d_otherError)});
+      ++count;
+    }
+  }
+  return entries;
+}
+
 static void registerAllStats1()
 {
   addGetStat("questions", &g_stats.qcounter);
@@ -1533,6 +1563,9 @@ static void registerAllStats1()
   addGetStat("auth-rcode-answers", []() {
     return toAuthRCodeStatsMap("auth-rcode-answers", g_stats.authRCode);
   });
+  addGetStat("remote-logger", []() {
+    return toRemoteLoggerStatsMap("remote-logger");
+  });
 }
 
 void registerAllStats()
index b3a07e7a877a453fe4a92d737b815da03c0e7b65..1e701b48878f34ea00064063587d964909d9f93a 100644 (file)
@@ -167,6 +167,9 @@ get-proxymapping-stats
 get-qtypelist
     Retrieves QType statistics. Queries from cache aren't being counted yet.
 
+get-remotelogger-stats
+    Retrieves the remote logger statistics, per type and address.
+
 hash-password [*WORK-FACTOR*]
     Asks for a password then returns the hashed and salted version,
     to use as a webserver password or API key. This command does
index 74f61f4c075380578c1147936a0a907b6571eba4..d1f76041365abb2a74678bc1812f814472e154d0 100644 (file)
@@ -1159,6 +1159,11 @@ const std::map<std::string, MetricDefinition> MetricDefinitionStorage::d_metrics
   {"auth-formerr-answers",
    MetricDefinition(PrometheusMetricType::multicounter,
                     "Count of RCodes returned by authoritative servers")},
+
+  // For multicounters, state the first
+  {"remote-logger-o-0",
+   MetricDefinition(PrometheusMetricType::multicounter,
+                    "Number of remote logging events")},
 };
 
 #define CHECK_PROMETHEUS_METRICS 0