]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/http: cleanup
authorMarek Vavrusa <marek@vavrusa.com>
Thu, 25 Aug 2016 17:41:29 +0000 (10:41 -0700)
committerMarek Vavrusa <marek@vavrusa.com>
Thu, 25 Aug 2016 17:41:29 +0000 (10:41 -0700)
modules/http/http.lua
modules/http/prometheus.lua
modules/http/static/kresd.js
modules/http/static/main.tpl

index b6b5dd07d124fe3a4e6fc3dec873837da381475b..f7b6c8f241efaab3d4a922cd0399260515451a33 100644 (file)
@@ -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
index a8d3300aa15ed15904b2791c3b92120d59ecd997..3831b3d298b875486b8e966b3564c7a4db156fbc 100644 (file)
@@ -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},
index 1cde645e95f2b7888e3283fdd92f580ae4faf332..da4cf75e96707282bf41c37c86341da375f1066b 100644 (file)
@@ -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;
index 558e02909afe5bedd8ec93d4ae230e15d238dee7..e4eebbd3c8c2193625a88606fe1e9b04e4d87ee9 100644 (file)
@@ -31,7 +31,6 @@
                </div>
                <ul class="nav navbar-nav navbar-right">
                        <li><a href="#">Metrics</a></li>
-                       <li><a href="#worldmap">World Map</a></li>
                        <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Modules <span class="caret"></span></a>
                                <ul class="dropdown-menu" id="modules-dropdown">
@@ -63,7 +62,7 @@
                                </div>
                        </div>
                        <div class="row">
-                               <h3>Running workers</h3>
+                               <h3>Instances</h3>
                                <div class="col-md-12">
                                <table id="workers" class="table table-responsive">
                                        <tr>
@@ -76,7 +75,7 @@
                </div>
                <div class="row" id="map-container">
                        <a name="worldmap"></a>
-                       <h2 class="sub-header">Where do the queries go?</h2>
+                       <h2 class="sub-header">Outbound queries</h2>
                        <div class="col-md-12">
                                <div id="map" style="position: relative;"></div>
                        </div>