From d745cd6fade612ae533c1b12e5709d1f4422bdb9 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sun, 22 Nov 2015 12:55:24 +0100 Subject: [PATCH] move dnsdist json stats to dumping all metrics, adjust built-in webpage to the new names of the old things --- pdns/dnsdist-web.cc | 36 +++++++++++++--------------------- pdns/dnsdistdist/html/local.js | 12 ++++++------ 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index e3685e9fc2..032c6d40d5 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -13,12 +13,6 @@ #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(&e.second)) + obj.insert({e.first, (int)(*val)->load()}); + else if (const auto& val = boost::get(&e.second)) + obj.insert({e.first, (**val)}); + else + obj.insert({e.first, (int)(*boost::get(&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); diff --git a/pdns/dnsdistdist/html/local.js b/pdns/dnsdistdist/html/local.js index 036db1e1f2..8ac3651353 100644 --- a/pdns/dnsdistdist/html/local.js +++ b/pdns/dnsdistdist/html/local.js @@ -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) -- 2.47.2