]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/http: stream stats and outbound name freq
authorMarek Vavrusa <marek@vavrusa.com>
Fri, 27 May 2016 07:34:23 +0000 (00:34 -0700)
committerMarek Vavrusa <marek@vavrusa.com>
Wed, 6 Jul 2016 06:33:38 +0000 (23:33 -0700)
modules/http/http.lua
modules/http/static/main.tpl
modules/http/static/tinyweb.js

index c431cbebdaa9856b4ace43d88ea5b3cf6a80c698..819e19165026354e4827bb86e669d3b90b0f90e6 100644 (file)
@@ -13,17 +13,26 @@ local M = {
 
 -- Load dependent modules
 if not stats then modules.load('stats') end
+-- Function to sort frequency list
+local function freqsort(a, b) return a.count < b.count end
 local function stream_stats(h, ws)
        local ok, prev = true, stats.list()
        while ok do
                -- Get current snapshot
-               local cur, update = stats.list(), {}
+               local cur, stats_dt = stats.list(), {}
                for k,v in pairs(cur) do
-                       update[k] = v - (prev[k] or 0)
+                       stats_dt[k] = v - (prev[k] or 0)
                end
                prev = cur
+               -- Update frequent query list
+               local cur, freq = stats.frequent(), {}
+               table.sort(cur, freqsort)
+               for i = 1,math.min(20, #cur) do
+                       table.insert(freq, cur[i])
+               end
                -- Publish stats updates periodically
-               ok = ws:send(tojson(update))
+               local push = tojson({stats=stats_dt,freq=freq})
+               ok = ws:send(push)
                cqueues.sleep(0.5)
        end
        ws:close()
index f0417a7a9f70e67c41d05b94866391c506a852a8..cf82794da67830cd22822fad6052f79877f1c3bd 100644 (file)
@@ -2,7 +2,7 @@
 <title>{{.Title}}</title>
 <style>
        body { font-family: 'Gill Sans', 'Gill Sans MT', Verdana, sans-serif; color: #555; }
-       h1, h2, h3 { line-height: 2em; color: #000; text-align: center; border-bottom: 1px solid #ccc; }
+       h1, h2, h3 { line-height: 1.5em; color: #000; text-align: center; border-bottom: 1px solid #ccc; }
        h1, h2, h3 { font-weight: 300; }
        th { text-align: left; font-weight: normal; margin-bottom: 0.5em; }
        #page { font-weight: 300; }
index bb542a34f9ce95df288ae997e20ee955dc37b2ad..6f4849c60d771cb6b88a4d1416b116215dad66d5 100644 (file)
@@ -38,6 +38,18 @@ window.onload = function() {
                }
                statsChart.push(next);
        }
+       function updateFeed(resp) {
+               var feed = $('#feed');
+               feed.children().remove();
+               feed.append('<tr><th>Query name</th><th>Type</th><th>Frequency</th></tr>')
+               for (i = 0; i < resp.length; ++i) {
+                       var row = $('<tr />');
+                       row.append('<td>' + resp[i].name + '</td>');
+                       row.append('<td>' + resp[i].type + '</td>');
+                       row.append('<td>' + resp[i].count + '</td>');
+                       feed.append(row);
+               }
+       }
 
        /* WebSocket endpoints */
        var wsStats = 'ws://' + location.host + '/stats';
@@ -45,6 +57,7 @@ window.onload = function() {
     var ws = new Socket(wsStats);
     ws.onmessage = function(evt) {
       var data = $.parseJSON(evt.data);
-      pushMetrics(data);
+      pushMetrics(data.stats);
+      updateFeed(data.freq)
     };
 }