system-health-monitor
Advanced tools
Comparing version 1.0.1 to 1.1.0
32
index.js
@@ -32,8 +32,8 @@ 'use strict'; | ||
constructor({checkInterval, mem, cpu}) { | ||
if (!Number.isSafeInteger(checkInterval) || checkInterval < 1) { | ||
throw new Error('field `checkInterval` is required must be an integer and more than 1'); | ||
constructor({checkIntervalMsec, mem, cpu}) { | ||
if (!Number.isSafeInteger(checkIntervalMsec) || checkIntervalMsec < 1) { | ||
throw new Error('field "checkIntervalMsec" is required must be an integer and more than 1'); | ||
} | ||
this._checkInterval = checkInterval; | ||
this._checkIntervalMsec = checkIntervalMsec; | ||
@@ -67,3 +67,3 @@ this._isMemOverloaded = undefined; | ||
this._healthScheduler = setInterval(this._determineHealthIndicators, this._checkInterval); | ||
this._healthScheduler = setInterval(this._determineHealthIndicators, this._checkIntervalMsec); | ||
this._status = SystemHealthMonitor.STATUS_STARTED; | ||
@@ -220,3 +220,3 @@ } | ||
if (typeof mem !== 'object') { | ||
throw new Error('field `mem` is required and must be an object'); | ||
throw new Error('field "mem" is required and must be an object'); | ||
} | ||
@@ -226,3 +226,3 @@ | ||
if (mem.minFree === undefined || !Number.isSafeInteger(mem.minFree) || mem.minFree <= 0) { | ||
throw new Error('mem.minFree field is required for threshold = fixed and must be more then 0'); | ||
throw new Error('"mem.minFree" field is required for threshold = fixed and must be more then 0'); | ||
} | ||
@@ -235,3 +235,5 @@ | ||
throw new Error('mem.highWatermark field is required for threshold = rate and must be in range (0;1)'); | ||
throw new Error( | ||
'"mem.highWatermark" field is required for threshold = rate and must be in range (0;1)' | ||
); | ||
} | ||
@@ -243,3 +245,3 @@ | ||
} else { | ||
throw new Error('mem.thresholdType is not set or has invalid type'); | ||
throw new Error('"mem.thresholdType" is not set or has invalid type'); | ||
} | ||
@@ -250,3 +252,3 @@ } | ||
if (typeof cpu !== 'object') { | ||
throw new Error('field `cpu` is required and must be an object'); | ||
throw new Error('field "cpu" is required and must be an object'); | ||
} | ||
@@ -256,3 +258,3 @@ | ||
if (!Number.isSafeInteger(cpu.periodPoints) || cpu.periodPoints < 1) { | ||
throw new Error('cpu.periodPoints field is required for SMA algorithm and must be more than 0'); | ||
throw new Error('"cpu.periodPoints" field is required for SMA algorithm and must be more than 0'); | ||
} | ||
@@ -263,3 +265,3 @@ this._cpuUsageCalculator = new CpuUsageSma(cpu.periodPoints); | ||
} else { | ||
throw new Error('cpu.calculationAlgo is not set or has invalid type'); | ||
throw new Error('"cpu.calculationAlgo" is not set or has invalid type'); | ||
} | ||
@@ -269,3 +271,5 @@ | ||
if (!cpu.highWatermark || !Number.isFinite(cpu.highWatermark) || cpu.highWatermark > 1) { | ||
throw new Error('cpu.highWatermark field is required for threshold = rate and must be in range (0,1]'); | ||
throw new Error( | ||
'"cpu.highWatermark" field is required for threshold = rate and must be in range (0,1]' | ||
); | ||
} | ||
@@ -277,3 +281,3 @@ | ||
} else { | ||
throw new Error('cpu.thresholdType is not set or has invalid type'); | ||
throw new Error('"cpu.thresholdType" is not set or has invalid type'); | ||
} | ||
@@ -280,0 +284,0 @@ } |
{ | ||
"name": "system-health-monitor", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "This module implements service that check RAM and CPU characteristics and decides according to passed config that instance is overloaded", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -46,3 +46,3 @@ # System Health Monitor for node | ||
const monitorConfig = { | ||
checkInterval: 1, | ||
checkIntervalMsec: 1000, | ||
mem: { | ||
@@ -68,3 +68,3 @@ thresholdType: 'none' | ||
This simple example checks system info every second (`checkInterval` option) and provides information about the | ||
This simple example checks system info every second (`checkIntervalMsec` option) and provides information about the | ||
current amount of free memory, total amount of memory, CPU usage (avg by cores) and amount of available cores. | ||
@@ -106,3 +106,3 @@ | ||
const monitorConfig = { | ||
checkInterval: 1, | ||
checkIntervalMsec: 1000, | ||
mem: { | ||
@@ -128,3 +128,3 @@ thresholdType: 'fixed', | ||
const monitorConfig = { | ||
checkInterval: 1, | ||
checkIntervalMsec: 1000, | ||
mem: { | ||
@@ -145,3 +145,3 @@ thresholdType: 'rate', | ||
Utilization of core over period is a result of division of the time the core was running user or kernel processes | ||
by amount of elapsed time between sequential checks during the period (controlled by `checkInterval` option). | ||
by amount of elapsed time between sequential checks during the period (controlled by `checkIntervalMsec` option). | ||
The average utilization is an arithmetical mean of utilization values of all available cores. | ||
@@ -169,3 +169,3 @@ | ||
const monitorConfig = { | ||
checkInterval: 1, | ||
checkIntervalMsec: 1000, | ||
mem: { | ||
@@ -188,3 +188,3 @@ thresholdType: 'rate', | ||
const monitorConfig = { | ||
checkInterval: 1, | ||
checkIntervalMsec: 1000, | ||
mem: { | ||
@@ -206,3 +206,3 @@ thresholdType: 'rate', | ||
**_Note!_** With `sma` strategy service stays overloaded for `checkInterval * cpu.periodPoints` and | ||
**_Note!_** With `sma` strategy service stays overloaded for `checkIntervalMsec * cpu.periodPoints` milliseconds and | ||
`monitor.getCpuUsage()` returns `100`. That's because the monitor has no data for sequential `cpu.periodPoints` periods. | ||
@@ -276,6 +276,6 @@ | ||
Let's consider that `checkInterval` is 1 second. To calculate avg usage for one-second-long period of time | ||
we need to calculate the current value and the value 1 second ago. | ||
Let's consider that `checkIntervalMsec` is 1000 ms. To calculate avg usage for one-second-long period of time | ||
we need to calculate the current value and the value 1000 ms ago. | ||
`usage` = `100.0 * (busy - prevBusy) / (work - prevWork)`. | ||
`monitor.getCpuUsage()` returns `usage` value for `last_value` strategy. |
@@ -15,3 +15,3 @@ /* eslint-disable max-len */ | ||
let checkerConf = { | ||
checkInterval: 15000, | ||
checkIntervalMsec: 15000, | ||
mem: { | ||
@@ -49,3 +49,3 @@ thresholdType: 'none', | ||
assert.equal(actualSchedulerClass, expectedSchedulerClass); | ||
assert.equal(systemMonitor._healthScheduler._repeat, checkerConf.checkInterval); | ||
assert.equal(systemMonitor._healthScheduler._repeat, checkerConf.checkIntervalMsec); | ||
}); | ||
@@ -52,0 +52,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38841
18
513