-
Notifications
You must be signed in to change notification settings - Fork 29
/
bell.js
75 lines (67 loc) · 2.44 KB
/
bell.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
70
71
72
73
74
75
/* Realtime anomalies detection based on statsd, for periodic time series.
* Copyright (c) 2014 Eleme, Inc. https://github.com/eleme/node-bell
*
* Usage: bell <service> [options]
*
* Options:
*
* -h, --help output usage information
* -V, --version output the version number
* -c, --configs <c> configs file path
* -l, --log-level <l> logging level (1~5 for debug~critical)
* -s, --sample-configs generate sample configs
*
* Data flow:
*
* [statsd]
* |
* v send to queue
* [listener] -----------------> [beanstalkd]
* |
* | reserve
* history metrics v record anomalies
* ---------------> [analyzers] ----------------
* | | |
* | | put to ssdb |
* | v |
* ------------------- [ssdb] <-----------------
* |
* |
* v
* [webapp]
*/
var co = require('co')
, fs = require('fs')
, program = require('commander')
, toml = require('toml')
, analyzer = require('./lib/analyzer')
, configs = require('./lib/configs')
, listener = require('./lib/listener')
, webapp = require('./lib/webapp')
, util = require('./lib/util')
, log = util.log
;
co(function *(){
program
.version('0.1.6')
.usage('<service> [options]')
.option('-c, --configs-path <c>', 'configs file path')
.option('-s, --sample-configs', 'generate sample configs file')
.option('-l, --log-level <l>', 'logging level (1~5 for critical~debug)', function(val){
return (parseInt(val, 10) - 1) % 5 + 1;
})
.parse(process.argv);
log.level = util.logLevels[program.logLevel || 4];
if (program.sampleConfigs) {
log.info('Generate sample.configs.toml to current directory');
return util.copy(util.path.configs, 'sample.configs.toml');
}
var configsPath = program.configsPath || util.path.configs;
var content = fs.readFileSync(configsPath).toString();
util.updateNestedObjects(configs, toml.parse(content));
var name = program.args[0];
if (!name) program.help();
var service = {listener: listener, analyzer: analyzer, webapp: webapp}[name];
if (!service) program.help();
else yield service.serve();
})();