Commit 4eef70fa authored by Marek Vavrusa's avatar Marek Vavrusa

modules/http: cleanup

parent 7df48e6c
......@@ -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
......
......@@ -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},
......
......@@ -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;
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment