Giter VIP home page Giter VIP logo

node-monitor-sensor's Introduction

Package: alinex-monitor-sensor

Build Status Coverage Status Dependency Status

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.

Install

The easiest way is to let npm add the module directly:

> npm install alinex-monitor-sensor --save

NPM

Usage

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.

Sensor run

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'
  }
}

Status

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%'

Warn/Fail rules

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"

Public API

Sensor classes

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

Methods

  • run(cb) - start a new analyzation with optional callback
  • format() - give a human readable output in markdown syntax

Events

  • error - then the sensor could not work properly
  • start - sensor has started
  • end - sensor ended analysis
  • ok - no problems found
  • warn - warning means high load or critical state
  • fail - not working correctly

Class properties

  • meta - some meta data for this test type
    • name - title of the test
    • description - short description what will be checked
    • category - to group similiar tests together
    • level - gives a hint if it is a low level or higher level test
  • values - meta information for the measurement values
  • config - 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)

Properties

  • config - configuration (given combined with defaults)
  • result - the results:
    • date - start date of last or current run
    • range - if set this will give the time range (start/end date in an array) this measurement includes
    • status - status of the last or current run (ok, warn, fail)
    • message - error message of the last or current run
    • values - map of measured values
    • analysis - additional analysis data

License

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

http://www.apache.org/licenses/LICENSE-2.0

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.