Browse Source

add custom config support

master
filesite-io 6 months ago
parent
commit
85e05bca59
  1. 7
      README.md
  2. 6
      monitor.mjs
  3. 8
      server.mjs

7
README.md

@ -31,6 +31,13 @@ npm install @@ -31,6 +31,13 @@ npm install
npm start
```
如需指定自定义配置文件启动:
```
npm start -- my_config.json
```
注意,配置文件必须是json格式,并且保存在conf/目录。
## 查看监控结果

6
monitor.mjs

@ -11,8 +11,9 @@ import md5 from 'md5'; @@ -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 { @@ -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) {

8
server.mjs

@ -2,7 +2,11 @@ import common from './lib/common.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();
})();
Loading…
Cancel
Save