From: Marek Vavrusa Date: Thu, 25 Aug 2016 17:41:29 +0000 (-0700) Subject: modules/http: cleanup X-Git-Tag: v1.2.0-rc1~107 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4eef70fa02a9ec2ea379beabb38ebd392faf139c;p=thirdparty%2Fknot-resolver.git modules/http: cleanup --- diff --git a/modules/http/http.lua b/modules/http/http.lua index b6b5dd07d..f7b6c8f24 100644 --- a/modules/http/http.lua +++ b/modules/http/http.lua @@ -34,6 +34,9 @@ local mime_types = { local function pgload(relpath, modname) if not modname then modname = 'http' end local fp, err = io.open(string.format('%s/%s/%s', moduledir, modname, relpath), 'r') + if not fp then + fp, err = io.open(string.format('%s/%s/static/%s', moduledir, modname, relpath), 'r') + end if not fp then error(err) end local data = fp:read('*all') fp:close() @@ -66,7 +69,7 @@ local pages = { local function serve_root() local data = pgload('main.tpl')[2] data = data - :gsub('{{ title }}', 'kresd @ '..hostname()) + :gsub('{{ title }}', title or ('kresd @ ' .. hostname())) :gsub('{{ host }}', hostname()) return function (h, stream) -- Render snippets @@ -97,6 +100,7 @@ local prometheus = require('prometheus') for k, v in pairs(prometheus.endpoints) do M.endpoints[k] = v end +M.prometheus = prometheus -- Export HTTP service page snippets M.snippets = {} @@ -322,6 +326,17 @@ function M.deinit() prometheus.deinit() end +-- @function Module runnable +function M.step(timeout) + local ok, err = cq:step(timeout) + return ok, err, cq:timeout() +end + +-- @function Module pollable fd +function M.pollfd() + return cq:pollfd() +end + -- @function Configure module function M.config(conf) if conf == true then conf = {} end diff --git a/modules/http/prometheus.lua b/modules/http/prometheus.lua index a8d3300aa..3831b3d29 100644 --- a/modules/http/prometheus.lua +++ b/modules/http/prometheus.lua @@ -8,7 +8,7 @@ local gauges = { } local function merge(t, results, prefix) - for x, result in pairs(results) do + for _, result in pairs(results) do if type(result) == 'table' then for k, v in pairs(result) do local val = t[prefix..k] @@ -64,7 +64,7 @@ local function snapshot_start(h, ws) end -- Aggregate per-worker metrics local wdata = {} - for i, info in pairs(map 'worker.info()') do + for _, info in pairs(map 'worker.info()') do if type(info) == 'table' then wdata[tostring(info.pid)] = {rss=info.rss, usertime=info.usertime, systime=info.systime, pagefaults=info.pagefaults, queries=info.queries} end @@ -144,6 +144,7 @@ end return { init = snapshot_start, deinit = snapshot_end, + gauges = gauges, endpoints = { ['/stats'] = {'application/json', getstats, stream_stats}, ['/frequent'] = {'application/json', function () return stats.frequent() end}, diff --git a/modules/http/static/kresd.js b/modules/http/static/kresd.js index 1cde645e9..da4cf75e9 100644 --- a/modules/http/static/kresd.js +++ b/modules/http/static/kresd.js @@ -55,10 +55,10 @@ $(function() { 'cache.miss': [6, 'Cache miss'], 'cache.insert': [7, 'Cache insert'], 'cache.delete': [8, 'Cache delete'], - 'worker.udp': [9, 'Outgoing UDP'], - 'worker.tcp': [10, 'Outgoing TCP'], - 'worker.ipv4': [11, 'Outgoing IPv4'], - 'worker.ipv6': [12, 'Outgoing IPv6'], + 'worker.udp': [9, 'UDP queries'], + 'worker.tcp': [10, 'TCP queries'], + 'worker.ipv4': [11, 'IPv4 queries'], + 'worker.ipv6': [12, 'IPv6 queries'], 'worker.concurrent': [13, 'Queries outstanding'], 'worker.queries': [14, 'Queries received/s'], 'worker.dropped': [15, 'Queries dropped'], @@ -163,7 +163,7 @@ $(function() { /* Realtime updates over WebSockets */ function pushMetrics(resp, now, buffer) { - var line = new Array(last_metric + 1); + var line = new Array(labels.length); line[0] = new Date(now * 1000); for (var lb in resp) { /* Push new datapoints */ @@ -305,6 +305,7 @@ $(function() { }, labels: ['x', '%user', '%sys'], labelsDiv: '', + stackedGraph: true, } ); workerData[pid].graph = workerGraph; diff --git a/modules/http/static/main.tpl b/modules/http/static/main.tpl index 558e02909..e4eebbd3c 100644 --- a/modules/http/static/main.tpl +++ b/modules/http/static/main.tpl @@ -31,7 +31,6 @@