Added Statistics
See: https://github.com/freifunkhamburg/ffffng/issues/24
This commit is contained in:
parent
2d5db51d24
commit
3c80be4d00
8 changed files with 203 additions and 0 deletions
server
|
@ -29,6 +29,7 @@ require('./utils/strings');
|
|||
require('./utils/urlBuilder');
|
||||
|
||||
require('./resources/versionResource');
|
||||
require('./resources/statisticsResource');
|
||||
require('./resources/frontendResource');
|
||||
require('./resources/taskResource');
|
||||
require('./resources/mailResource');
|
||||
|
|
26
server/resources/statisticsResource.js
Normal file
26
server/resources/statisticsResource.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng').factory('StatisticsResource', function (
|
||||
Logger,
|
||||
NodeService,
|
||||
Resources,
|
||||
ErrorTypes
|
||||
) {
|
||||
return {
|
||||
get: function (req, res) {
|
||||
NodeService.getNodeStatistics(function (err, nodeStatistics) {
|
||||
if (err) {
|
||||
Logger.tag('statistics').error('Error getting statistics:', err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
|
||||
return Resources.success(
|
||||
res,
|
||||
{
|
||||
nodes: nodeStatistics
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -3,6 +3,7 @@
|
|||
angular.module('ffffng').factory('Router', function (
|
||||
app,
|
||||
VersionResource,
|
||||
StatisticsResource,
|
||||
FrontendResource,
|
||||
NodeResource,
|
||||
MonitoringResource,
|
||||
|
@ -23,6 +24,8 @@ angular.module('ffffng').factory('Router', function (
|
|||
app.put('/api/monitoring/confirm/:token', MonitoringResource.confirm);
|
||||
app.put('/api/monitoring/disable/:token', MonitoringResource.disable);
|
||||
|
||||
app.get('/internal/api/statistics', StatisticsResource.get);
|
||||
|
||||
app.get('/internal/api/tasks', TaskResource.getAll);
|
||||
app.put('/internal/api/tasks/run/:id', TaskResource.run);
|
||||
app.put('/internal/api/tasks/enable/:id', TaskResource.enable);
|
||||
|
|
|
@ -490,6 +490,45 @@ angular.module('ffffng')
|
|||
callback
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
getNodeStatistics: function (callback) {
|
||||
this.getAllNodes(function (err, nodes) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var nodeStatistics = {
|
||||
registered: _.size(nodes),
|
||||
withVPN: 0,
|
||||
withCoords: 0,
|
||||
monitoring: {
|
||||
active: 0,
|
||||
pending: 0
|
||||
}
|
||||
};
|
||||
|
||||
_.each(nodes, function (node) {
|
||||
if (node.key) {
|
||||
nodeStatistics.withVPN += 1;
|
||||
}
|
||||
|
||||
if (node.coords) {
|
||||
nodeStatistics.withCoords += 1;
|
||||
}
|
||||
|
||||
switch (node.monitoringState) {
|
||||
case 'active':
|
||||
nodeStatistics.monitoring.active += 1;
|
||||
break;
|
||||
case 'pending':
|
||||
nodeStatistics.monitoring.pending += 1;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
callback(null, nodeStatistics);
|
||||
})
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue