From: bert hubert Date: Tue, 3 Mar 2015 20:44:15 +0000 (+0100) Subject: spent an injustifiable amount of time making graphs.. X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~88^2~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=178c03ce24202cce8791d892c3dc6e79bf140f65;p=thirdparty%2Fpdns.git spent an injustifiable amount of time making graphs.. --- diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index c866fcc390..6708d6c339 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -155,6 +155,32 @@ This is still much in flux, but for now, try: * `topResponses(20, 2)`: top-20 servfail responses (use ,3 for NXDOMAIN) +Live histogram of latency +------------------------- +``` +> showResponseLatency() +Average response latency: 78.84 msec, median: 87.59 msec + msec + 0.10 + 0.20 . + 0.40 ********************** + 0.80 *********** + 1.60 . + 3.20 + 6.40 . + 12.80 * + 25.60 * + 51.20 * + 102.40 ********************************************************************** + 204.80 ************************* + 409.60 ** + 819.20 : +1638.40 . +``` + +Where : stands for 'half a star' and . for 'less than half a star, but +something was there'. + Per domain or subnet QPS limiting --------------------------------- If certain domains or source addresses are generating onerous amounts of diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 117001f516..67af8a60bd 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -19,6 +19,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include +#include +#include + #include "ext/luawrapper/include/LuaContext.hpp" #include #include "sstuff.hh" @@ -27,7 +32,8 @@ #include "statbag.hh" #include #include -#include + + #include #include #include @@ -1284,6 +1290,60 @@ void setupLua(bool client) g_lua.executeCode(R"(function topResponses(top, kind, labels) for k,v in ipairs(getTopResponses(top, kind, labels)) do show(string.format("%4d %-40s %4d %4.1f%%",k,v[1],v[2], v[3])) end end)"); + g_lua.writeFunction("showResponseLatency", []() { + + map histo; + double bin=100; + for(int i=0; i < 15; ++i) { + histo[bin]; + bin*=2; + } + + using namespace boost::accumulators; + + typedef boost::accumulators::accumulator_set< + unsigned int + , stats + > acc_t; + acc_t lats; + + { + std::lock_guard lock(g_rings.respMutex); + + for(const auto& r : g_rings.respRing) { + auto iter = histo.lower_bound(r.usec); + if(iter != histo.end()) + iter->second++; + else + histo.rbegin()++; + lats(r.usec); + } + } + + g_outputBuffer = (boost::format("Average response latency: %.02f msec, median: %.02f msec\n") % (0.001*mean(lats)) % (0.001*median(lats))).str(); + double highest=0; + + for(auto iter = histo.cbegin(); iter != histo.cend(); ++iter) { + highest=std::max(highest, iter->second*1.0); + } + boost::format fmt("%7.2f\t%s\n"); + g_outputBuffer += (fmt % "msec" % "").str(); + + for(auto iter = histo.cbegin(); iter != histo.cend(); ++iter) { + int stars = (70.0 * iter->second/highest); + char c='*'; + if(!stars && iter->second) { + stars=1; // you get 1 . to show something is there.. + if(70.0*iter->second/highest > 0.5) + c=':'; + else + c='.'; + } + g_outputBuffer += (fmt % (iter->first/1000.0) % string(stars, c)).str(); + } + }); g_lua.writeFunction("newQPSLimiter", [](int rate, int burst) { return QPSLimiter(rate, burst); }); g_lua.registerFunction("check", &QPSLimiter::check);