"use strict";
var gdata={}
$(document).ready(function() {
$.ajaxSetup({ cache: false });
var qpsgraph = new Rickshaw.Graph( {
element: document.getElementById("qpschart"),
width: 400,
height: 200,
renderer: 'line',
series: new Rickshaw.Series.FixedDuration([{ name: 'servfailps' }, {name: 'qps'}], undefined, {
timeInterval: 1000,
maxDataPoints: 100,
timeBase: new Date().getTime() / 1000
})
} );
var y_ticks = new Rickshaw.Graph.Axis.Y( {
graph: qpsgraph,
orientation: 'left',
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
element: document.getElementById('qpsy_axis')
} );
qpsgraph.render();
var cpugraph = new Rickshaw.Graph( {
element: document.getElementById("cpuchart"),
width: 400,
height: 200,
renderer: 'line',
series: new Rickshaw.Series.FixedDuration([{ name: 'one' }, {name: 'two'}], undefined, {
timeInterval: 1000,
maxDataPoints: 100,
timeBase: new Date().getTime() / 1000
})
} );
var y_ticks = new Rickshaw.Graph.Axis.Y( {
graph: cpugraph,
orientation: 'left',
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
element: document.getElementById('cpuy_axis')
} );
cpugraph.render();
var intervalcount=0;
function updateRingBuffers()
{
var filtered=$("#filter1").is(':checked')
var qstring='jsonstat?command=get-query-ring&name=queries';
if(filtered)
qstring=qstring+"&public-filtered=1";
$.getJSON(qstring,
function(data) {
console.log(data);
var bouw="
Number | Domain | Type |
";
var num=0;
var total=0, rest=0;
$.each(data["entries"], function(a,b) {
total+=b[0];
if(num++ > 10) {
rest+=b[0];
return;
}
if(b[1].length > 25)
b[1]=b[1].substring(0,25);
bouw=bouw+(""+b[0]+" | "+b[1]+" | "+b[2]+" |
");
});
bouw+=""+rest+" | Rest |
";
bouw=bouw+"
";
$("#queryring").html(bouw);
});
filtered=$("#filter2").is(':checked')
qstring='jsonstat?command=get-query-ring&name=servfail-queries';
if(filtered)
qstring=qstring+"&public-filtered=1";
$.getJSON(qstring,
function(data) {
var bouw="Number | Servfail domain | Type |
";
var num=0, total=0, rest=0;
$.each(data["entries"], function(a,b) {
total+=b[0];
if(num++ > 10) {
rest+=b[0];
return;
}
if(b[1].length > 25)
b[1]=b[1].substring(0,25);
bouw=bouw+(""+b[0]+" | "+b[1]+" | "+b[2]+" |
");
});
bouw+=""+rest+" | Rest |
";
bouw=bouw+"
";
$("#servfailqueryring").html(bouw);
});
$.getJSON('jsonstat?command=get-remote-ring&name=remotes',
function(data) {
var bouw="Number | Remote |
";
var num=0, total=0, rest=0;
$.each(data["entries"], function(a,b) {
total+=b[0];
if(num++ > 10) {
rest +=b[0];
return;
}
bouw=bouw+(""+b[0]+" | "+b[1]+" |
");
});
bouw+=""+rest+" | Rest |
";
bouw=bouw+"
";
$("#remotering").html(bouw);
});
$.getJSON('jsonstat?command=get-remote-ring&name=servfail-remotes',
function(data) {
var bouw="Number | Servfail Remote |
";
var num=0, total=0, rest=0;
$.each(data["entries"], function(a,b) {
total+=b[0];
if(num++ > 10) {
rest += b[0];
return;
}
bouw=bouw+(""+b[0]+" | "+b[1]+" |
");
});
bouw+=""+rest+" | Rest |
";
bouw=bouw+"
";
$("#servfailremotering").html(bouw);
});
}
function update()
{
$.ajax({
url: 'jsonstat?command=stats',
type: 'GET',
dataType: 'json',
jsonp: false,
success: function(data, x, y) {
$("#questions").text(data["queries"]);
$("#acl-drops").text(data["acl-drops"]);
$("#dyn-drops").text(data["dyn-blocked"]);
$("#rule-drops").text(data["rule-drop"]);
$("#uptime").text(moment.duration(data["uptime"]*1000.0).humanize());
$("#latency").text((data["latency-avg10000"]/1000.0).toFixed(2));
if(!gdata["cpu-sys-msec"])
gdata=data;
var cpu=((1.0*data["cpu-sys-msec"]+1.0*data["cpu-user-msec"] - 1.0*gdata["cpu-sys-msec"]-1.0*gdata["cpu-user-msec"])/10.0);
$("#cpu").text(cpu.toFixed(2));
var qps=1.0*data["queries"]-1.0*gdata["queries"];
$("#qps").text(qps.toFixed(2));
$("#server-policy").text(data["server-policy"]);
var servfailps=1.0*data["servfail-responses"]-1.0*gdata["servfail-responses"];
var totpcache=1.0*data["cache-hits"]-1.0*gdata["cache-hits"]+1.0*data["cache-misses"]-1.0*gdata["cache-misses"];
var hitrate=0;
if(totpcache > 0) {
hitrate=100.0*(data["cache-hits"]-1.0*gdata["cache-hits"])/totpcache;
$("#phitrate").text(hitrate.toFixed(2));
}
else
$("#phitrate").text(0);
qpsgraph.series.addData({ qps: qps, servfailps: servfailps});
qpsgraph.render();
cpugraph.series.addData({ one: cpu, two: hitrate});
cpugraph.render();
gdata=data;
},
error: function() {
},
});
$.ajax({ url: 'api/v1/servers/localhost', type: 'GET', dataType: 'json', jsonp: false,
success: function(data) {
$("#version").text(data["daemon_type"]+" "+data["version"]);
$("#acl").text(data["acl"]);
$("#local").text(data["local"]);
var bouw='# | Name | Address | Status | Latency | Queries | Drops | QPS | Out | Weight | Order | Pools |
';
$.each(data["servers"], function(a,b) {
bouw = bouw + (""+b["id"]+" | "+b["name"]+" | "+b["address"]+" | "+b["state"]+" | ");
var latency = (b["latency"] === null) ? 0.0 : b["latency"];
bouw = bouw + (""+latency.toFixed(2)+" | "+b["queries"]+" | "+b["reuseds"]+" | "+(b["qps"]).toFixed(2)+" | "+b["outstanding"]+" | ");
bouw = bouw + (""+b["weight"]+" | "+b["order"]+" | "+b["pools"]+" |
");
});
bouw = bouw + "
";
$("#downstreams").html(bouw);
bouw='# | Rule | Action | Matches |
';
if(data["rules"].length) {
$.each(data["rules"], function(a,b) {
bouw = bouw + (""+b["id"]+" | "+b["rule"]+" | "+b["action"]+" | ");
bouw = bouw + (""+b["matches"]+" |
");
});
}
else
bouw = bouw + 'No rules defined |
';
bouw = bouw + "
";
$("#rules").html(bouw);
bouw='# | Response Rule | Action | Matches |
';
if(data["response-rules"].length) {
$.each(data["response-rules"], function(a,b) {
bouw = bouw + (""+b["id"]+" | "+b["rule"]+" | "+b["action"]+" | ");
bouw = bouw + (""+b["matches"]+" |
");
});
}
else
bouw = bouw + 'No response rules defined |
';
bouw = bouw + "
";
$("#response-rules").html(bouw);
}
});
// if((intervalcount++)%5)
// return;
// updateRingBuffers();
$.ajax({ url: 'jsonstat?command=dynblocklist', type: 'GET', dataType: 'json', jsonp: false,
success: function(data) {
var bouw='Dyn blocked netmask | Seconds | Blocks | Reason |
';
var gotsome=false;
$.each(data, function(a,b) {
bouw=bouw+(""+a+" | "+b.seconds+" | "+b.blocks+" | "+b.reason+" |
");
gotsome=true;
});
if(!gotsome)
bouw = bouw + 'No dynamic blocks active |
';
bouw=bouw+"
";
$("#dynblock").html(bouw);
}});
$.ajax({ url: 'jsonstat?command=ebpfblocklist', type: 'GET', dataType: 'json', jsonp: false,
success: function(data) {
var bouw='Kernel-based dyn blocked netmask | Seconds | Blocks |
';
var gotsome=false;
$.each(data, function(a,b) {
bouw=bouw+(""+a+" | "+b.seconds+" | "+b.blocks+" |
");
gotsome=true;
});
if(!gotsome)
bouw = bouw + 'No eBPF blocks active |
';
bouw=bouw+"
";
$("#ebpfblock").html(bouw);
}});
};
$("#filter1").click(updateRingBuffers);
$("#filter2").click(updateRingBuffers);
update();
setInterval(update, 1000);
});