Skip to content

Commit

Permalink
Merge pull request #25 from UnownHash/monitor-switch
Browse files Browse the repository at this point in the history
feat(monitor): allow to switch it off
  • Loading branch information
lenisko authored Dec 9, 2023
2 parents f3e1551 + 2836645 commit 495457d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"consoleStatus": false
},
"monitor": {
"enabled": true,
"reboot": false,
"minMemory": 30000,
"maxMemStartMultiple": 2,
Expand Down
2 changes: 2 additions & 0 deletions config/local.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"host": "127.0.0.1"
},
"monitor":{
"enabled": true,
// when enabled reboot instead restart
"reboot": false,
// min required memory
"minMemory": 30000,
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface Config {
consoleStatus: boolean;
};
monitor: {
enabled: boolean;
reboot: boolean;
minMemory: number;
maxMemStartMultiple: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ wssDevice.on('connection', (ws, req) => {
const memoryStatus = await device.getMemoryUsage();
log.info(`${device.deviceId}/${device.instanceNo}:Memory = ${JSON.stringify(memoryStatus)}`);
let restartRequired = false;
if (memoryStatus.memFree && memoryStatus.memFree < config.monitor.minMemory) {
if (config.monitor.enabled && memoryStatus.memFree && memoryStatus.memFree < config.monitor.minMemory) {
log.warn(
`${device.deviceId}/${device.instanceNo}: ${memoryStatus.memFree} < ${config.monitor.minMemory} - RESTART REQUIRED`,
);
Expand All @@ -97,7 +97,7 @@ wssDevice.on('connection', (ws, req) => {
? config.monitor.maxMemStartMultipleOverwrite[prefix]
: config.monitor.maxMemStartMultiple;

if (memoryStatus.memMitm > memoryStatus.memStart * value) {
if (config.monitor.enabled && memoryStatus.memMitm > memoryStatus.memStart * value) {
log.warn(
`${device.deviceId}/${device.instanceNo}: ${memoryStatus.memMitm} > ${memoryStatus.memStart} * ${value} - RESTART REQUIRED`,
);
Expand Down

0 comments on commit 495457d

Please sign in to comment.