refactor services check to use on/off and let monitor decide colors
This commit is contained in:
parent
f4dbeb4b7e
commit
9ce25d7651
|
@ -30,7 +30,7 @@ class Engine {
|
||||||
|
|
||||||
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger});
|
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger});
|
||||||
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
|
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
|
||||||
return cb({name: 'Embark ' + self.version, status: 'green'});
|
return cb({name: 'Embark ' + self.version, status: 'on'});
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ class Engine {
|
||||||
|
|
||||||
self.servicesMonitor.addCheck('Webserver', function (cb) {
|
self.servicesMonitor.addCheck('Webserver', function (cb) {
|
||||||
let devServer = 'Webserver (http://' + host + ':' + port + ')';
|
let devServer = 'Webserver (http://' + host + ':' + port + ')';
|
||||||
return cb({name: devServer, status: 'green'});
|
return cb({name: devServer, status: 'on'});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.start(function () {
|
server.start(function () {
|
||||||
|
@ -190,24 +190,24 @@ class Engine {
|
||||||
try {
|
try {
|
||||||
let parsed = JSON.parse(body);
|
let parsed = JSON.parse(body);
|
||||||
if (parsed.Version) {
|
if (parsed.Version) {
|
||||||
return cb({name: ("IPFS " + parsed.Version), status: 'green'});
|
return cb({name: ("IPFS " + parsed.Version), status: 'on'});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return cb({name: "IPFS ", status: 'green'});
|
return cb({name: "IPFS ", status: 'on'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return cb({name: "IPFS ", status: 'red'});
|
return cb({name: "IPFS ", status: 'off'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
res.on('error', function (err) {
|
res.on('error', function (err) {
|
||||||
self.logger.trace("Check IPFS version error: " + err);
|
self.logger.trace("Check IPFS version error: " + err);
|
||||||
return cb({name: "IPFS ", status: 'red'});
|
return cb({name: "IPFS ", status: 'off'});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return cb({name: "IPFS ", status: 'red'});
|
return cb({name: "IPFS ", status: 'off'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -226,19 +226,19 @@ class Engine {
|
||||||
if (self.web3.isConnected()) {
|
if (self.web3.isConnected()) {
|
||||||
return cb({
|
return cb({
|
||||||
name: (self.web3.version.node.split("/")[0] + " " + self.web3.version.node.split("/")[1].split("-")[0] + " (Ethereum)"),
|
name: (self.web3.version.node.split("/")[0] + " " + self.web3.version.node.split("/")[1].split("-")[0] + " (Ethereum)"),
|
||||||
status: 'green'
|
status: 'on'
|
||||||
});
|
});
|
||||||
} else {
|
} 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.servicesMonitor.addCheck('Whisper', function (cb) {
|
||||||
self.web3.version.getWhisper(function (err, res) {
|
self.web3.version.getWhisper(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb({name: 'Whisper', status: 'red'});
|
return cb({name: 'Whisper', status: 'off'});
|
||||||
} else {
|
} else {
|
||||||
return cb({name: 'Whisper', status: 'green'});
|
return cb({name: 'Whisper', status: 'on'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
let async = require('../utils/async_extend.js');
|
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 {
|
class ServicesMonitor {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
|
@ -23,14 +20,13 @@ ServicesMonitor.prototype.initCheck = function (checkName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.events.on('check:' + checkName, function (obj) {
|
self.events.on('check:' + checkName, function (obj) {
|
||||||
// TODO: see todo above
|
if (check && check.status === 'off' && obj.status === 'on') {
|
||||||
if (check && check.status === 'red' && obj.status === 'green') {
|
|
||||||
self.events.emit('check:backOnline:' + checkName);
|
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.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;
|
check.status = obj.status;
|
||||||
self.events.emit("servicesState", self.checkState);
|
self.events.emit("servicesState", self.checkState);
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,9 +43,16 @@ class Dashboard {
|
||||||
|
|
||||||
availableServices(_services) {
|
availableServices(_services) {
|
||||||
let services = [];
|
let services = [];
|
||||||
let checkName;
|
let check;
|
||||||
for (checkName in _services) {
|
for (check in _services) {
|
||||||
services.push(_services[checkName]);
|
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'));
|
this.progress.setContent(services.join('\n'));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = function(embark) {
|
module.exports = function(embark) {
|
||||||
embark.registerServiceCheck('PluginService', function(cb) {
|
embark.registerServiceCheck('PluginService', function(cb) {
|
||||||
cb({name: "ServiceName", status: "green"});
|
cb({name: "ServiceName", status: "on"});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue