]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
move dnsdist json stats to dumping all metrics, adjust built-in webpage to the new...
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 22 Nov 2015 11:55:24 +0000 (12:55 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 22 Nov 2015 11:55:24 +0000 (12:55 +0100)
pdns/dnsdist-web.cc
pdns/dnsdistdist/html/local.js

index e3685e9fc239ace1b8400a59ff16907d0944d003..032c6d40d525c3d01c56c3996dd068c7cf9b1615 100644 (file)
 #include "htmlfiles.h"
 #include "base64.hh"
 
-static time_t s_start=time(0);
-static int uptimeOfProcess()
-{
-  return time(0) - s_start;
-}
-
 
 bool compareAuthorization(YaHTTP::Request& req, const string &expected_password)
 {
@@ -83,27 +77,25 @@ static void connectionThread(int sock, ComboAddress remote, string password)
 
     }
     else if(command=="stats") {
-      struct rusage ru;
-      getrusage(RUSAGE_SELF, &ru);
-
       resp.status=200;
-      Json my_json = Json::object {
-       { "questions", (int)g_stats.queries },
-       { "servfail-answers", (int)g_stats.servfailResponses },
+
+      auto obj=Json::object {
        { "packetcache-hits", 0},
        { "packetcache-misses", 0},
-       { "user-msec", (int)(ru.ru_utime.tv_sec*1000ULL + ru.ru_utime.tv_usec/1000) },
-       { "sys-msec", (int)(ru.ru_stime.tv_sec*1000ULL + ru.ru_stime.tv_usec/1000) },
        { "over-capacity-drops", 0 },
-       { "too-old-drops", 0 },
-       { "uptime", uptimeOfProcess()},
-       { "qa-latency", (int)g_stats.latencyAvg1000},
-       { "qa-latency1000", (int)g_stats.latencyAvg1000},
-       { "qa-latency10000", (int)g_stats.latencyAvg10000},
-       { "qa-latency1000000", (int)g_stats.latencyAvg1000000},
-       { "something", Json::array { 1, 2, 3 } },
+       { "too-old-drops", 0 }
       };
 
+      for(const auto& e : g_stats.entries) {
+       if(const auto& val = boost::get<DNSDistStats::stat_t*>(&e.second))
+         obj.insert({e.first, (int)(*val)->load()});
+       else if (const auto& val = boost::get<double*>(&e.second))
+         obj.insert({e.first, (**val)});
+       else
+         obj.insert({e.first, (int)(*boost::get<DNSDistStats::statfunction_t>(&e.second))(e.first)});
+      }
+      Json my_json = obj;
+
       resp.headers["Content-Type"] = "application/json";
       resp.body=my_json.dump();
     }
@@ -201,7 +193,7 @@ static void connectionThread(int sock, ComboAddress remote, string password)
 }
 void dnsdistWebserverThread(int sock, const ComboAddress& local, const std::string& password)
 {
-  infolog("Webserver launched on %s", local.toStringWithPort());
+  warnlog("Webserver launched on %s", local.toStringWithPort());
   for(;;) {
     try {
       ComboAddress remote(local);
index 036db1e1f20f6fb04ab8e9e34ade2418331562e7..8ac365135329f77b0f2d97cd3ebf9c20fc1a9519 100644 (file)
@@ -148,21 +148,21 @@ $(document).ready(function() {
             type: 'GET',
             dataType: 'jsonp',
             success: function(data, x, y) {
-               $("#questions").text(data["questions"]);
+               $("#questions").text(data["queries"]);
                $("#over-capacity-drops").text(data["over-capacity-drops"]);
                $("#too-old").text(data["too-old-drops"]);
                $("#uptime").text(moment.duration(data["uptime"]*1000.0).humanize());
-               $("#latency").text(data["qa-latency"]/1000.0);
-               if(!gdata["sys-msec"]) 
+               $("#latency").text(data["latency-avg100"]/1000.0);
+               if(!gdata["cpu-sys-msec"]) 
                    gdata=data;
 
-               var cpu=((1.0*data["sys-msec"]+1.0*data["user-msec"] - 1.0*gdata["sys-msec"]-1.0*gdata["user-msec"])/10.0);
+               var cpu=((1.0*data["cpu-sys-msec"]+1.0*data["cpu-user-msec"] - 1.0*gdata["cpu-sys-msec"]-1.0*gdata["cpu-user-msec"])/10.0);
 
                $("#cpu").text(cpu.toFixed(2));
-               var qps=1.0*data["questions"]-1.0*gdata["questions"];
+               var qps=1.0*data["queries"]-1.0*gdata["queries"];
                $("#qps").text(qps);
 
-               var servfailps=1.0*data["servfail-answers"]-1.0*gdata["servfail-answers"];
+               var servfailps=1.0*data["servfail-responses"]-1.0*gdata["servfail-responses"];
 
                var totpcache=1.0*data["packetcache-hits"]-1.0*gdata["packetcache-hits"]+1.0*data["packetcache-misses"]-1.0*gdata["packetcache-misses"];
                if(totpcache > 0)