This module is part of the Monitoring modules and applications but can be used as standalone module in other projects, too.
- it has multiple sensors
- runs completely asynchronous
- collects all the data
- supports verbose mode and debugging
- calculates the status
Some sensors and parts of it are specifically for Linux/Unix/OSX systems. If you have windows you may help to improve this.
It is one of the modules of the Alinex Universe following the code standards defined there.
The easiest way is to let npm add the module directly:
> npm install alinex-monitor-sensor --save
To use one of the sensors you have to load the sensors collection:
var sensor = require('alinex-monitor-sensor');
Or you may only load one specific sensor class:
var Ping = require('alinex-monitor-sensor/lib/ping');
In the further documentation i will show usage with the sensor collection.
To use any sensor you have to instantiate and configure it:
var ping = new sensor.Ping({
ip: '193.99.144.80'
});
You may also give a alinex-config object here.
Now you can start it using a callback method:
ping.run(function(err, sensor) {
// do something with result in ping object
console.log(sensor);
});
Or alternatively you may use an event based call:
ping.run();
ping.on 'end', function() {
// do something with result in ping object
console.log(ping);
});
The ping
object looks like:
{ config: { verbose: false, timeout: 1, ip: '137.168.111.222' },
result:
{ date: Tue Jul 22 2014 14:08:34 GMT+0200 (CEST),
status: 'fail',
data: '1 packets transmitted, 0 received, 100% packet loss, time 0ms',
message: 'Ping exited with code 1'
}
}
The sensors uses the following status:
- running if the sensor is already analyzing, you have to wait
- ok if everything is perfect, there nothing have to be done
- warn if the sensor reached the warning level, know you have to keep an eye on it
- fail if the sensor failed and there is a problem
Each sensor will automatically fail if an timeout occurred. Else the defined checks will be used.
Most checks will collect different values which may be used to specify the status.
Therefore you may write a rule for fail
or warn
status in logical form, use
a simple expression syntax:
fail: 'free < 5%'
warn: 'free < 20% and cpu > 50%'
You may use different mathematical and logical operators together with braces. Allowed are:
- comparison: <, >, <=, >=, ==, !=
- calculation: +, -, *, /
- logic: and, or, is, isnt, not
- braces: (, )
- all the data value names of the sensor
- array access on some data values:
match[1]
- object access on some data values:
match.title
More complexer examples are:
fail: "match.title isnt 'heise Developer'"
warn: "free < 10% or swapFree < 50%"
fail: "statuscode < 200 or statuscode >= 400"
The following list contains the possible sensors, look into each other to get all the specific information:
- Cpu - cpu activity check
- Load - cpu load check
- Memory - check free memory
- IO - disk io check
- Net - network io check
- Diskfree - free disk space
- Time - check local time
- Upgrade - check for package upgrades
- Ping - network ping test
- Socket - test port connectivity
- Http - try requesting an url
run(cb)
- start a new analyzation with optional callbackformat()
- give a human readable output in markdown syntax
error
- then the sensor could not work properlystart
- sensor has startedend
- sensor ended analysisok
- no problems foundwarn
- warning means high load or critical statefail
- not working correctly
meta
- some meta data for this test typename
- title of the testdescription
- short description what will be checkedcategory
- to group similiar tests togetherlevel
- gives a hint if it is a low level or higher level test
values
- meta information for the measurement valuesconfig
- the default configuration (each entry starting with underscore gives the help text for that value)check
- check function for the configuration values (alinex-config style)
config
- configuration (given combined with defaults)result
- the results:date
- start date of last or current runrange
- if set this will give the time range (start/end date in an array) this measurement includesstatus
- status of the last or current run (ok, warn, fail)message
- error message of the last or current runvalues
- map of measured valuesanalysis
- additional analysis data
Copyright 2014 Alexander Schilling
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.