]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: worker publishes usage information
authorMarek Vavrusa <marek@vavrusa.com>
Tue, 5 Jul 2016 07:33:24 +0000 (00:33 -0700)
committerMarek Vavrusa <marek@vavrusa.com>
Wed, 6 Jul 2016 06:33:38 +0000 (23:33 -0700)
daemon/bindings.c
daemon/lua/sandbox.lua

index 28190a6f93b3137743f00a08ae691087439e0d26..2534b55409f1d98fb3a080ef1175dbdb061d9ec8 100644 (file)
@@ -997,6 +997,11 @@ static int wrk_resolve(lua_State *L)
        return 1;
 }
 
+static inline double getseconds(uv_timeval_t *tv)
+{
+       return (double)tv->tv_sec + 0.000001*((double)tv->tv_usec);
+}
+
 /** Return worker statistics. */
 static int wrk_stats(lua_State *L)
 {
@@ -1021,6 +1026,26 @@ static int wrk_stats(lua_State *L)
        lua_setfield(L, -2, "dropped");
        lua_pushnumber(L, worker->stats.timeout);
        lua_setfield(L, -2, "timeout");
+       /* Add subset of rusage that represents counters. */
+       uv_rusage_t rusage;
+       if (uv_getrusage(&rusage) == 0) {
+               lua_pushnumber(L, getseconds(&rusage.ru_utime));
+               lua_setfield(L, -2, "usertime");
+               lua_pushnumber(L, getseconds(&rusage.ru_stime));
+               lua_setfield(L, -2, "systime");
+               lua_pushnumber(L, rusage.ru_majflt);
+               lua_setfield(L, -2, "pagefaults");
+               lua_pushnumber(L, rusage.ru_nswap);
+               lua_setfield(L, -2, "swaps");
+               lua_pushnumber(L, rusage.ru_nvcsw + rusage.ru_nivcsw);
+               lua_setfield(L, -2, "csw");
+       }
+       /* Get RSS */
+       size_t rss = 0;
+       if (uv_resident_set_memory(&rss) == 0) {
+               lua_pushnumber(L, rss);
+               lua_setfield(L, -2, "rss");
+       }
        return 1;
 }
 
index 2bffa8d38a3a656876477c3efa255ca4d209510b..41a9130ce9af189e628dcb543b619787313e0cca 100644 (file)
@@ -29,6 +29,13 @@ if rawget(kres, 'str2dname') ~= nil then
        todname = kres.str2dname
 end
 
+-- Shorthand for aggregated per-worker information
+worker.info = function ()
+       local t = worker.stats()
+       t.pid = worker.pid
+       return t
+end
+
 -- Resolver mode of operation
 local current_mode = 'normal'
 local mode_table = { normal=0, strict=1, permissive=2 }