Nicer logging + Monitoring progress

This commit is contained in:
baldo 2016-05-24 19:14:09 +02:00
parent a82b66c637
commit 09b01f5ccf
5 changed files with 47 additions and 22 deletions

View file

@ -7,7 +7,9 @@
"peersPath": "/tmp/peers", "peersPath": "/tmp/peers",
"logging": { "logging": {
"directory": "/tmp/logs" "directory": "/tmp/logs",
"debug": false,
"logRequests": false
}, },
"email": { "email": {
@ -25,7 +27,7 @@
}, },
"map": { "map": {
"nodesJsonUrl": "https://map.hamburg.freifunk.net/nodes.json" "nodesJsonUrl": "http://musterstadt.freifunk.net/nodes.json"
} }
}, },
"client": { "client": {
@ -37,6 +39,9 @@
"map": { "map": {
"mapUrl": "http://map.hamburg.freifunk.net" "mapUrl": "http://map.hamburg.freifunk.net"
}, },
"monitoring": {
"enabled": false
},
"coordsSelector": { "coordsSelector": {
"lat": 53.565278, "lat": 53.565278,
"lng": 10.001389, "lng": 10.001389,

View file

@ -12,7 +12,9 @@ var defaultConfig = {
peersPath: '/tmp/peers', peersPath: '/tmp/peers',
logging: { logging: {
directory: '/tmp/logs' directory: '/tmp/logs',
debug: false,
logRequests: false
}, },
email: { email: {
@ -44,7 +46,7 @@ var defaultConfig = {
mapUrl: 'http://map.musterstadt.freifunk.net' mapUrl: 'http://map.musterstadt.freifunk.net'
}, },
monitoring: { monitoring: {
enabled: true enabled: false
}, },
coordsSelector: { coordsSelector: {
showInfo: false, showInfo: false,

View file

@ -8,7 +8,7 @@ _.each(jobFiles, function (jobFile) {
require(jobFile); require(jobFile);
}); });
angular.module('ffffng').factory('Scheduler', function ($injector, Logger) { angular.module('ffffng').factory('Scheduler', function ($injector, Logger, config) {
var cron = require('node-cron'); var cron = require('node-cron');
function schedule(expr, jobName) { function schedule(expr, jobName) {
@ -29,10 +29,13 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger) {
try { try {
schedule('0 */1 * * * *', 'MailQueueJob'); schedule('0 */1 * * * *', 'MailQueueJob');
if (config.client.monitoring.enabled) {
// schedule('0 */5 * * * *', 'NodeInformationRetrievalJob'); // schedule('0 */5 * * * *', 'NodeInformationRetrievalJob');
schedule('*/10 * * * * *', 'NodeInformationRetrievalJob'); schedule('*/10 * * * * *', 'NodeInformationRetrievalJob');
// schedule('0 */1 * * * *', 'NodeInformationCleanupJob'); // schedule('0 */1 * * * *', 'NodeInformationCleanupJob');
} }
}
catch (error) { catch (error) {
Logger.tag('jobs').error('Error during scheduling of background jobs:', error); Logger.tag('jobs').error('Error during scheduling of background jobs:', error);
throw error; throw error;

View file

@ -2,26 +2,34 @@
var config = require('./config'); var config = require('./config');
var scribe = require('scribe-js')({
app: 'ffffng',
id: process.pid,
rootPath: config.server.logging.directory, // Hack to allow proper logging of Error.
Object.defineProperty(Error.prototype, 'message', {
module: { configurable: true,
'router/Viewer': { enumerable: true
username: false, });
password: false Object.defineProperty(Error.prototype, 'stack', {
} configurable: true,
} enumerable: true
}); });
var scribe = require('scribe-js')({
rootPath: config.server.logging.directory,
});
if (config.server.logging.debug) {
process.console.addLogger('debug', 'grey', { process.console.addLogger('debug', 'grey', {
logInConsole: false logInConsole: false
}); });
} else {
process.console.debug = function () {};
}
angular.module('ffffng').factory('Logger', function (app) { angular.module('ffffng').factory('Logger', function (app) {
if (config.server.logging.logRequests) {
app.use(scribe.express.logger()); app.use(scribe.express.logger());
}
app.use('/internal/logs', scribe.webPanel()); app.use('/internal/logs', scribe.webPanel());
return process.console; return process.console;

View file

@ -241,6 +241,13 @@ angular.module('ffffng')
return callback(err); return callback(err);
} }
if (response.statusCode !== 200) {
return callback(new Error(
'Could not download nodes.json from ' + url + ': ' +
response.statusCode + ' - ' + response.statusMessage
));
}
parseNodesJson(body, function (err, data) { parseNodesJson(body, function (err, data) {
if (err) { if (err) {
return callback(err); return callback(err);