Commit 8e50cdfd authored by Cool Fire's avatar Cool Fire

Add stats for VPN

parent f2923e2a
......@@ -19,6 +19,11 @@ function fetch() {
ircLineData = JSON.parse(fs.readFileSync('irc_loads.json', 'utf8'));
ircLine.setData(ircLineData);
vpnrates = JSON.parse(fs.readFileSync('vpn_bitrate.json', 'utf8'))[0];
vpnsparkline.setData(['IN', 'OUT'], vpnrates)
vpndonut.setData(JSON.parse(fs.readFileSync('vpn_bitrate_now.json', 'utf8')));
}
var line = grid.set(0, 0, 2, 2, contrib.line,
......@@ -34,7 +39,7 @@ var line = grid.set(0, 0, 2, 2, contrib.line,
showLegend: true,
label: 'Main server load'
}
)
);
var dockerLine = grid.set(0, 2, 1, 2, contrib.line,
{ style:
......@@ -49,9 +54,9 @@ var dockerLine = grid.set(0, 2, 1, 2, contrib.line,
showLegend: false,
label: 'Docker swarm load'
}
)
);
var ircLine = grid.set(2, 2, 1, 2, contrib.line,
var ircLine = grid.set(1, 2, 1, 2, contrib.line,
{ style:
{
line: "yellow",
......@@ -61,22 +66,35 @@ var ircLine = grid.set(2, 2, 1, 2, contrib.line,
wholeNumbersOnly: false,
xLabelPadding: 3,
xPadding: 5,
showLegend: false,
showLegend: true,
label: 'IRC servers load'
}
)
);
var lineData = null;
var dockerLineData = null;
var ircLineData = null;
var vpnsparkline = grid.set(2, 0, 1, 1, contrib.sparkline,
{
label: 'VPN throughput',
tags: true,
style: { fg: 'blue', titleFg: 'white' }
}
);
var vpndonut = grid.set(2, 1, 1, 1, contrib.donut,
{
label: 'VPN utilization'
}
);
fetch();
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
screen.render()
setInterval(
......
......@@ -18,6 +18,14 @@ def addload(servers)
loads
end
def addport(servers)
ports = []
servers.each do |server|
ports.push([[],[]])
end
ports
end
def getloads(servers, loads)
servers.each_with_index do |server, i|
@influxdb.query "SELECT \"time\",\"5min\" FROM \"ucd_load\" WHERE \"hostname\" = '#{server[2]}' AND time > now() - 4h" do |_name, _tags, points|
......@@ -33,6 +41,24 @@ def getloads(servers, loads)
loads
end
def getports(servers, ports)
servers.each_with_index do |server, i|
@influxdb.query "SELECT \"time\",\"ifInOctets_rate\",\"ifOutOctets_rate\" FROM \"ports\" WHERE \"hostname\" = '#{server[2]}' AND \"ifName\" = '#{server[3]}' AND time > now() - 4h" do |_name, _tags, points|
points.each do |point|
dt = DateTime.parse(point['time'])
stamp = sprintf "%02d:%02d", dt.hour + 1, dt.minute
inrate = sprintf "%.2f", (point['ifInOctets_rate'].to_f * 8 / 1024 / 1024)
outrate = sprintf "%.2f", (point['ifOutOctets_rate'].to_f * 8 / 1024 / 1024)
ports[i][0].push inrate
ports[i][1].push outrate
end
end
end
ports
end
main_servers = [
['Lydia6', 'red', 'lydia6.insomnia247.nl'],
['Freya', 'yellow', 'freya.insomnia247.nl'],
......@@ -64,3 +90,16 @@ irc_servers = [
irc_loads = addload(irc_servers)
irc_loads = getloads(irc_servers, irc_loads)
File.write 'irc_loads.json', irc_loads.to_json
vpn_ports = [
['VPN', '', '10.0.1.10', 'tun0']
]
vpn_bitrate = addport(vpn_ports)
vpn_bitrate = getports(vpn_ports, vpn_bitrate)
File.write 'vpn_bitrate.json', vpn_bitrate.to_json
File.write('vpn_bitrate_now.json', [
{'percent': (vpn_bitrate[0][0].last).to_f / 100, label: 'IN', 'color': 'green'},
{'percent': (vpn_bitrate[0][1].last).to_f / 100, label: 'OUT','color': 'cyan'}
].to_json)
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