Added status page

This commit is contained in:
Martin Schröder 2015-05-21 15:27:01 +02:00 committed by Martin Schröder
parent 4b2eb0c2e1
commit 94eedf07bd
3 changed files with 80 additions and 117 deletions

View file

@ -11,7 +11,7 @@
_timeouts[name] = i;
},
repeat: function(name, t, fn){
var i = setTimeout(function _onTimeout(){
function _onTimeout(){
fn(function next(ret, err){
if(ret){
clearTimeout(i);
@ -21,7 +21,8 @@
setTimeout(_onTimeout, t);
}
});
}, t);
}
var i = setTimeout(_onTimeout, t); _onTimeout();
_timeouts[name] = i;
},
$clearAll: function(){

View file

@ -1,14 +1,46 @@
<luci-layout-with-sidebar>
<div ng-controller="StatsOverviewCtrl">
<h2>Status</h2>
<luci-table
title="{{'System'|translate}}"
data="systemStatusTbl"></luci-table>
<luci-table
title="{{'Memory'|translate}}"
data="systemMemoryTbl"></luci-table>
<luci-table
title="{{'Storage'|translate}}"
data="systemStorageTbl"></luci-table>
<luci-config-section>
<luci-config-heading>{{ 'Status' | translate }}</luci-config-heading>
<luci-config-info>{{ 'status.status.info' | translate }}</luci-config-info>
</luci-config-section>
<div class="panel panel-default" ng-repeat="sec in sections" ng-show="sec.interface">
<div class="panel-heading">
<div class="btn-group pull-right">
<!--<span class="btn pull-right" ng-show="sec.interface.up" ng-click="expanded = !expanded">
<i class="fa fa-caret-down fa-2x" ng-show="expanded"></i>
<i class="fa fa-caret-left fa-2x" ng-hide="expanded"></i>
</span>-->
<span ng-show="sec.interface.up" class="btn pull-right"><i style="color: green;" class="fa fa-check-circle fa-2x"></i></span>
<span ng-show="sec.interface.pending" class="btn pull-right"><i style="color: orange;" class="fa fa-spinner fa-2x fa-spin"></i></span>
<span ng-show="!sec.interface.up && !sec.interface.pending" class="btn pull-right"><i style="color: red;" class="fa fa-exclamation-circle fa-2x"></i></span>
</div>
<h3 class="panel-title" style="font-size: 1.5em; padding-top: 0.4em; font-weight: bold; font-family: 'vodafont';">
{{sec.name | translate}}
</h3>
<div style="clear: both;"></div>
</div>
<div class="panel-body "> <!-- ng-show="sec.interface.up && expanded" >-->
<div ng-show="sec.interface.errors" class="alert alert-danger">
<ul>
<li ng-repeat="err in sec.interface.errors">{{err.subsystem}}: {{err.code}}</li>
</ul>
</div>
<luci-config-lines ng-hide="sec.interface.errors" >
<luci-config-line title="{{'IP Address'|translate}}">
<strong>{{sec.interface["ipv4-address"][0].address}}</strong>
</luci-config-line>
<luci-config-line title="{{'Gateway'|translate}}" ng-show="sec.interface['route'][0].nexthop">
<strong>{{sec.interface["route"][0].nexthop}}</strong>
</luci-config-line>
<luci-config-line title="{{'Primary DNS'|translate}}" ng-show="sec.interface['dns-server'][0]">
<strong>{{sec.interface["dns-server"][0]}}</strong>
</luci-config-line>
<luci-config-line title="{{'Secondary DNS'|translate}}" ng-show="sec.interface['dns-server'][1]">
<strong>{{sec.interface["dns-server"][1]}}</strong>
</luci-config-line>
</luci-config-lines>
</div>
</div>
</div>
</luci-layout-with-sidebar>

View file

@ -1,114 +1,44 @@
//! Author: Martin K. Schröder <mkschreder.uk@gmail.com>
JUCI.app
.controller("StatsOverviewCtrl", function ($scope, $session, $rootScope, $rpc, gettext, $tr) {
$scope.sysinfo = {};
$scope.info = {};
.controller("StatsOverviewCtrl", function ($scope, $uci, $rpc, gettext) {
//$scope.expanded = false;
$scope.sections = [{}, {}, {}];
$scope.systemStatusTbl = {
rows: [["", ""]]
};
$scope.systemExtStatusTbl = {
rows: [["", ""]]
};
$scope.systemMemoryTbl = {
rows: [["", ""]]
};
$scope.systemStorageTbl = {
rows: [["", ""]]
};
$scope.systemConnectionsTbl = {
rows: [["", ""]]
};
$scope.systemDHCPLeasesTbl = {
columns: [gettext("Hostname"), gettext("IPv4-Address"), gettext("MAC-Address"), gettext("Leasetime remaining")],
rows: [
[gettext("No active leases"), '', '', '']
]
};
$scope.systemStationsTbl = {
columns: [gettext("IPv4-Address"), gettext("MAC address"), gettext("Signal"), gettext("Noise"), gettext("RX Rate"), gettext("TX Rate")],
rows: []
};
var info = {};
var sys = {};
var conntrack = {};
var disk = {};
var clients = {};
var leases = {};
function doUpdate(){
async.parallel([
function (cb){$rpc.router.info().done(function(res){info = res; cb();}).fail(function(res){cb();});},
function (cb){$rpc.system.info().done(function(res){sys = res; cb();}).fail(function(res){cb();});},
function (cb){$rpc.luci2.network.conntrack_count().done(function(res){conntrack = res; cb();}).fail(function(res){cb();});},
function (cb){$rpc.luci2.system.diskfree().done(function(res){disk = res; cb();}).fail(function(res){cb();});},
function (cb){$rpc.router.clients().done(function(res){clients = res; cb();}).fail(function(res){cb();});},
function (cb){$rpc.luci2.network.dhcp_leases().done(function(res){leases = res.leases || []; cb();}).fail(function(res){cb();});}
], function(err, next){
$scope.systemStatusTbl.rows = [
[$tr(gettext("Hostname")), info.system.name],
[$tr(gettext("Model")), info.system.nvramver],
[$tr(gettext("Firmware Version")), info.system.firmware],
[$tr(gettext("Kernel Version")), info.system.kernel],
[$tr(gettext("Local Time")), new Date(sys.localtime)],
[$tr(gettext("Uptime")), info.system.uptime],
//[$tr(gettext("Load Average")), sys.load[0] + " " + sys.load[1] + " " + sys.load[2]]
];
$scope.systemExtStatusTbl.rows = [
[$tr(gettext("Wifi")), (info.specs.wifi)?gettext("yes"):gettext("no")],
[$tr(gettext("ADSL")), (info.specs.adsl)?gettext("yes"):gettext("no")],
[$tr(gettext("VDSL")), (info.specs.vdsl)?gettext("yes"):gettext("no")],
[$tr(gettext("Voice")), (info.specs.voice)?gettext("yes"):gettext("no")],
[$tr(gettext("Voice Ports")), info.specs.voice_ports],
[$tr(gettext("Ethernet Ports")), info.specs.eth_ports]
];
$scope.systemMemoryTbl.rows = [
[$tr(gettext("Usage")), '<luci-progress value="'+Math.round((sys.memory.total - sys.memory.free) / 1000)+'" total="'+ Math.round(sys.memory.total / 1000) +'" units="kB"></luci-progress>'],
[$tr(gettext("Shared")), '<luci-progress value="'+Math.round(sys.memory.shared / 1000)+'" total="'+ Math.round(sys.memory.total / 1000) +'" units="kB"></luci-progress>'],
[$tr(gettext("Buffered")), '<luci-progress value="'+Math.round(sys.memory.buffered / 1000)+'" total="'+ Math.round(sys.memory.total / 1000) +'" units="kB"></luci-progress>'],
[$tr(gettext("Swap")), '<luci-progress value="'+Math.round((sys.swap.total - sys.swap.free) / 1000)+'" total="'+ Math.round(sys.swap.total / 1000) +'" units="kB"></luci-progress>']
];
$scope.systemStorageTbl.rows = [
[$tr(gettext("Root Usage (/)")), '<luci-progress value="'+Math.round(disk.root.used / 1000)+'" total="'+ Math.round(disk.root.total / 1000) +'" units="kB"></luci-progress>'],
[$tr(gettext("Temporary Usage (/tmp)")), '<luci-progress value="'+Math.round(disk.tmp.used / 1000)+'" total="'+ Math.round(disk.tmp.total / 1000) +'" units="kB"></luci-progress>']
];
$scope.systemConnectionsTbl.rows = [
[$tr(gettext("Active Connections")), '<luci-progress value="'+ conntrack.count +'" total="'+conntrack.limit+'"></luci-progress>']
];
if(leases.length){
$scope.systemDHCPLeasesTbl.rows = [];
leases.map(function(lease){
var date = new Date(null);
date.setSeconds(lease.expires); // specify value for SECONDS here
var time = date.toISOString().substr(11, 8);
$scope.systemDHCPLeasesTbl.rows.push(
[lease.hostname, lease.ipaddr, lease.macaddr, time]
);
JUCI.interval.repeat("status.refresh", 2000, function(resume){
async.series([
function(next){
$uci.sync("boardpanel").done(function(){ next(); });
},
function(next){
$rpc.network.interface.dump().done(function(result){
_interfaces = result.interface;
next();
});
} else {
$scope.systemDHCPLeasesTbl.rows = [
[$tr(gettext("No active leases")), '', '', '']
];
}
if(Object.keys(clients).length){
$scope.systemStationsTbl.rows = [];
Object.keys(clients).map(function(id){
var cl = clients[id];
$scope.systemStationsTbl.rows.push(
[cl.ipaddr, cl.macaddr, 0, 0, cl.rx_rate || 0, cl.tx_rate || 0]
);
},
function(next){
var sections = [];
[
{ name: gettext("Internet"), value: $uci.boardpanel.network.internet.value||"wan" },
{ name: gettext("Voice"), value: $uci.boardpanel.network.voice.value },
{ name: gettext("IPTV"), value: $uci.boardpanel.network.iptv.value }
]
.filter(function(x){ return x.value != "" })
.forEach(function(x, c){
sections.push({
"name": x.name,
"interface": _interfaces.find(function(i){ return i.interface == x.value; })
});
});
} else {
$scope.systemStationsTbl.rows = [
[$tr(gettext("No active stations")), '', '', '', '', '']
];
sections = sections.sort(function(a, b) { return a.interface.up > b.interface.up; });
for(var c = 0; c < $scope.sections.length; c++){
Object.assign($scope.sections[c], sections[c]);
}
$scope.$apply();
next();
}
$scope.$apply();
}, function(){
setTimeout(function(){
doUpdate();
}, 5000);
], function(){
resume();
});
}
doUpdate();
});
});