diff --git a/README.md b/README.md index 566be21..7caf358 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,13 @@ npm install npm start ``` +如需指定自定义配置文件启动: +``` +npm start -- my_config.json +``` + +注意,配置文件必须是json格式,并且保存在conf/目录。 + ## 查看监控结果 diff --git a/monitor.mjs b/monitor.mjs index fb62b21..33701c3 100644 --- a/monitor.mjs +++ b/monitor.mjs @@ -11,8 +11,9 @@ import md5 from 'md5'; class Monitor { //构造函数,设置默认配置 - constructor() { + constructor(configFilename) { this.config = null; + this.configFile = typeof(configFilename) != 'undefined' && configFilename ? configFilename : 'config.json'; //默认配置 this.systemLogDir = 'log/'; //系统日志保存目录 @@ -27,7 +28,8 @@ class Monitor { const _self = this; if ( !this.config || (typeof(forceReload) != 'undefined' && forceReload) ) { - let config = await common.getConfigFromJsonFile('config.json'); + console.log("Load config from %s", this.configFile); + let config = await common.getConfigFromJsonFile(this.configFile); //覆盖默认配置 for (const key in config) { diff --git a/server.mjs b/server.mjs index 6ec1ee0..2e75a82 100644 --- a/server.mjs +++ b/server.mjs @@ -2,7 +2,11 @@ import common from './lib/common.mjs'; import Monitor from './monitor.mjs'; (async () => { - let monitor = new Monitor(); - await monitor.init(); + let configFile = 'config.json'; + if (process.argv.length >= 3) { + configFile = process.argv[2]; + } + let monitor = new Monitor(configFile); + await monitor.init(); })(); \ No newline at end of file