refactor services check to use on/off and let monitor decide colors

This commit is contained in:
Iuri Matias 2017-04-01 23:22:43 -04:00
parent f4dbeb4b7e
commit 9ce25d7651
4 changed files with 25 additions and 22 deletions

View File

@ -30,7 +30,7 @@ class Engine {
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger});
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
return cb({name: 'Embark ' + self.version, status: 'green'});
return cb({name: 'Embark ' + self.version, status: 'on'});
}, 0);
}
@ -166,7 +166,7 @@ class Engine {
self.servicesMonitor.addCheck('Webserver', function (cb) {
let devServer = 'Webserver (http://' + host + ':' + port + ')';
return cb({name: devServer, status: 'green'});
return cb({name: devServer, status: 'on'});
});
server.start(function () {
@ -190,24 +190,24 @@ class Engine {
try {
let parsed = JSON.parse(body);
if (parsed.Version) {
return cb({name: ("IPFS " + parsed.Version), status: 'green'});
return cb({name: ("IPFS " + parsed.Version), status: 'on'});
}
else {
return cb({name: "IPFS ", status: 'green'});
return cb({name: "IPFS ", status: 'on'});
}
}
catch (e) {
return cb({name: "IPFS ", status: 'red'});
return cb({name: "IPFS ", status: 'off'});
}
});
res.on('error', function (err) {
self.logger.trace("Check IPFS version error: " + err);
return cb({name: "IPFS ", status: 'red'});
return cb({name: "IPFS ", status: 'off'});
});
});
}
else {
return cb({name: "IPFS ", status: 'red'});
return cb({name: "IPFS ", status: 'off'});
}
});
});
@ -226,19 +226,19 @@ class Engine {
if (self.web3.isConnected()) {
return cb({
name: (self.web3.version.node.split("/")[0] + " " + self.web3.version.node.split("/")[1].split("-")[0] + " (Ethereum)"),
status: 'green'
status: 'on'
});
} else {
return cb({name: "No Blockchain node found", status: 'red'});
return cb({name: "No Blockchain node found", status: 'off'});
}
});
self.servicesMonitor.addCheck('Whisper', function (cb) {
self.web3.version.getWhisper(function (err, res) {
if (err) {
return cb({name: 'Whisper', status: 'red'});
return cb({name: 'Whisper', status: 'off'});
} else {
return cb({name: 'Whisper', status: 'green'});
return cb({name: 'Whisper', status: 'on'});
}
});
});

View File

@ -1,8 +1,5 @@
let async = require('../utils/async_extend.js');
// TODO: need to separate colors from states
// i.e use status: /on|off|warn/ not /red|green/
// it's up to the logger or console to determine the color
class ServicesMonitor {
constructor(options) {
this.events = options.events;
@ -23,14 +20,13 @@ ServicesMonitor.prototype.initCheck = function (checkName) {
}
self.events.on('check:' + checkName, function (obj) {
// TODO: see todo above
if (check && check.status === 'red' && obj.status === 'green') {
if (check && check.status === 'off' && obj.status === 'on') {
self.events.emit('check:backOnline:' + checkName);
}
if (check && check.status === 'green' && obj.status === 'red') {
if (check && check.status === 'on' && obj.status === 'off') {
self.events.emit('check:wentOffline:' + checkName);
}
self.checkState[checkName] = obj.name[obj.status];
self.checkState[checkName] = {name: obj.name, status: obj.status};
check.status = obj.status;
self.events.emit("servicesState", self.checkState);
});

View File

@ -43,9 +43,16 @@ class Dashboard {
availableServices(_services) {
let services = [];
let checkName;
for (checkName in _services) {
services.push(_services[checkName]);
let check;
for (check in _services) {
let checkObj = _services[check];
if (checkObj.status === 'on') {
services.push(checkObj.name.green);
} else if (checkObj.status === 'off') {
services.push(checkObj.name.red);
} else {
services.push(checkObj.name);
}
}
this.progress.setContent(services.join('\n'));

View File

@ -1,5 +1,5 @@
module.exports = function(embark) {
embark.registerServiceCheck('PluginService', function(cb) {
cb({name: "ServiceName", status: "green"});
cb({name: "ServiceName", status: "on"});
});
};