-
Notifications
You must be signed in to change notification settings - Fork 49
/
monitor.js
69 lines (57 loc) · 2.18 KB
/
monitor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// monitor.js (c) 2010-2014 Loren West and other contributors
// May be freely distributed under the MIT license.
// For further details and documentation:
// http://lorenwest.github.com/node-monitor
(function(root){
// Load dependencies
var Monitor = require('./lib/index'),
log = Monitor.getLogger('monitor'),
stat = Monitor.getStatLogger('monitor'),
OS = require('os');
/**
* Bootstrap for a standalone monitor server
*
* @static
* @class server
*/
console.log("");
console.log(" __________");
console.log("_______ ___________________(_)_ /______________ ");
console.log("__ __ `__ \\ __ \\_ __ \\_ /_ __/ __ \\_ ___/");
console.log("_ / / / / / /_/ / / / / / / /_ / /_/ / /");
console.log("/_/ /_/ /_/\\____//_/ /_//_/ \\__/ \\____//_/");
console.log("");
// Boot the monitor server.
// This accepts websocket connections on the configured port.
var server = new Monitor.Server();
server.start(function(error) {
if (error) {
log.error('monitor.start', error);
return;
}
var connectTo = Monitor.Config.Monitor.allowExternalConnections ? OS.hostname() : 'localhost';
console.log('Monitor service started on host: ' + connectTo);
// Output security concerns
if (!Monitor.Config.Monitor.allowExternalConnections) {
console.log("");
console.log("External connections disabled.");
console.log("See " + process.cwd() + "/config/external.js for more information.");
}
});
// Process uncaught exceptions.
process.on('uncaughtException', function(err){
// On laptop sleep/startup the DNS servers aren't immediately available,
// resulting in a flood of these for socket.io until DNS services are back up.
if (err.message === 'ECONNREFUSED, Could not contact DNS servers') {
return;
}
// Don't allow the process to continue in an unknown state.
log.fatal('moniotor.uncaught', 'Uncaught Exception: ' + err.message);
log.fatal('moniotor.uncaught', err.stack);
server.stop(function(){
process.exit(1);
});
// Don't wait around if the server is hung.
setTimeout(function(){process.exit(1);}, 2000);
});
}(this));