]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/ws-api.cc
Merge pull request #8223 from PowerDNS/omoerbeek-patch-1
[thirdparty/pdns.git] / pdns / ws-api.cc
index 54776cd1e3b89bf0691ed2bfa9954d79c2272ec8..54dde00791283a1525a55aec8e4e94d5f73db71d 100644 (file)
@@ -24,7 +24,6 @@
 #endif
 
 #include <boost/tokenizer.hpp>
-#include <boost/circular_buffer.hpp>
 #include "namespaces.hh"
 #include "ws-api.hh"
 #include "json.hh"
@@ -159,14 +158,29 @@ void apiServerStatistics(HttpRequest* req, HttpResponse* resp) {
   if(req->method != "GET")
     throw HttpMethodNotAllowedException();
 
+  Json::array doc;
+  string name = req->getvars["statistic"];
+  if (!name.empty()) {
+    auto stat = productServerStatisticsFetch(name);
+    if (!stat) {
+      throw ApiException("Unknown statistic name");
+    }
+
+    doc.push_back(Json::object {
+      { "type", "StatisticItem" },
+      { "name", name },
+      { "value", std::to_string(*stat) },
+    });
+
+    resp->setBody(doc);
+
+    return;
+  }
+
   typedef map<string, string> stat_items_t;
   stat_items_t general_stats;
   productServerStatisticsFetch(general_stats);
 
-  auto resp_qtype_stats = g_rs.getQTypeResponseCounts();
-  auto resp_size_stats = g_rs.getSizeResponseCounts();
-
-  Json::array doc;
   for(const auto& item : general_stats) {
     doc.push_back(Json::object {
       { "type", "StatisticItem" },
@@ -175,6 +189,9 @@ void apiServerStatistics(HttpRequest* req, HttpResponse* resp) {
     });
   }
 
+  auto resp_qtype_stats = g_rs.getQTypeResponseCounts();
+  auto resp_size_stats = g_rs.getSizeResponseCounts();
+  auto resp_rcode_stats = g_rs.getRCodeResponseCounts();
   {
     Json::array values;
     for(const auto& item : resp_qtype_stats) {
@@ -188,7 +205,7 @@ void apiServerStatistics(HttpRequest* req, HttpResponse* resp) {
 
     doc.push_back(Json::object {
       { "type", "MapStatisticItem" },
-      { "name", "queries-by-qtype" },
+      { "name", "response-by-qtype" },
       { "value", values },
     });
   }
@@ -212,6 +229,24 @@ void apiServerStatistics(HttpRequest* req, HttpResponse* resp) {
     });
   }
 
+  {
+    Json::array values;
+    for(const auto& item : resp_rcode_stats) {
+      if (item.second == 0)
+        continue;
+      values.push_back(Json::object {
+        { "name", RCode::to_s(item.first) },
+        { "value", std::to_string(item.second) },
+      });
+    }
+
+    doc.push_back(Json::object {
+      { "type", "MapStatisticItem" },
+      { "name", "response-by-rcode" },
+      { "value", values },
+    });
+  }
+
 #ifndef RECURSOR
   for(const auto& ringName : S.listRings()) {
     Json::array values;