Git Product home page Git Product logo

liipmonitor's Introduction

Liip Monitor

This library provides shareable and reusable health checks. It ha been deprecated in favor of zendframework/ZendDiagnostics.

For integration into Symfony2 see the Liip Monitor Bundle.

The idea is that you fork this project and add your own health checks that you think they can useful for someone else project. This library provides a set of interfaces and a runner class to execute the health checks. On top of that it also provides a set of health check implementations (see the list below).

Installation

To get the source of this library simply use git:

# get source
git clone git://github.com/liip/LiipMonitor.git
cd LiipMonitor

To add this library to an existing project it is recommended to use the composer installer. Add the following to your projects composer.json:

"require": {
    ..
    "liip/monitor": "dev-master"
},

Get the composer installer if its not yet installed on your system and run update

# install dependencies
curl -s http://getcomposer.org/installer | php
php composer.phar update liip/monitor

Check groups

Checks can be grouped by implementing the getGroup method of the CheckInterface. By grouping checks it's possible to implement end-user status pages which provide feedback but hide implementation details, similar to status.github.com.

Available Health Checks

DiscUsageCheck

Checks if the maximum disc usage in percentage is reached.

DoctrineDbalCheck

Checks if a doctrine dbal server is running.

HttpServiceCheck

Checks if an http server is running on the host, port and path specified in the service configuration, returning the expected status code and content.

MemcacheCheck

Checks if a memcache server is running on the host and port specified in the service configuration.

RedisCheck

Checks if a redis server is running on the host and port specified in the service configuration.

PhpExtensionsCheck

Checks if the extensions specified in the service configuration are enabled in your PHP installation.

ProcessActiveCheck

Checks if a process containing a phrase specified in the service configuration is running on the machine.

SecurityAdvisoryCheck

Checks any composer dependency has an open security advisory.

WritableDirectoryCheck

Checks if the user executing the script is able to write in the given directory.

RabbitMQCheck

Checks if a rabbitmq server is running on the host and port specified in the service configuration, for declared user/password/vhost.

Writing Health Checks

Let's see an example on how to implement a health check class. In this case we are going to test for the availability of PHP Extensions:

namespace Acme\Hello\Check;

use Liip\Monitor\Check\Check;
use Liip\Monitor\Exception\CheckFailedException;
use Liip\Monitor\Result\CheckResult;

class PhpExtensionsCheck extends Check
{
    protected $extensions;

    public function __construct($extensions)
    {
        $this->extensions = $extensions;
    }

    public function check()
    {
        try {
            foreach ($this->extensions as $extension) {
                if (!extension_loaded($extension)) {
                    throw new CheckFailedException(sprintf('Extension %s not loaded', $extension));
                }
            }
            return $this->buildResult('OK', CheckResult::OK);
        } catch (\Exception $e) {
            return $this->buildResult(sprintf('KO - %s', $e->getMessage()), CheckResult::CRITICAL);
        }
    }

    public function getName()
    {
        return "PHP Extensions Health Check";
    }
}

Once you implemented the class then it's time to register the check service with your runner:

$checkChain = new \Liip\Monitor\Check\CheckChain();
$runner = new \Liip\Monitor\Check\Runner($checkChain);

$phpExtensionCheck = new \Acme\Hello\Check\PhpExtensionsCheck(array('apc', 'memcached'));
$checkChain->addCheck('php_extension_check', $phpExtensionCheck);

Finally to run health checks use:

$runner->runAllChecks() // runs all checks
$runner->runCheckById('php_extension_check'); // runs an individual check by id

To get a list of available checks use:

$chain->getAvailableChecks();

CheckResult values

These values has been taken from the nagios documentation :

  • CheckResult::OK - The plugin was able to check the service and it appeared to be functioning properly
  • CheckResult::WARNING - The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not appear to be working properly
  • CheckResult::CRITICAL - The plugin detected that either the service was not running or it was above some "critical" threshold
  • CheckResult::UNKNOWN - Invalid command line arguments were supplied to the plugin or low-level failures internal to the plugin (such as unable to fork, or open a tcp socket) that prevent it from performing the specified operation. Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states.

As you can see our constructor will take an array with the names of the extensions our application requires. Then on the check method it will iterate over that array to test for each of the extensions. If there are no problems then the check will return a CheckResult object with a message (OK in our case) and the result status (CheckResult::SUCCESS in our case). As you can see this is as easy as it gets.

Contributions

Fork this project, add a health check and then open a pull request.

Note to contributors

BY CONTRIBUTING TO THE LiipMonitor SOURCE CODE REPOSITORY YOU AGREE TO LICENSE YOUR CONTRIBUTION UNDER THE TERMS OF THE MIT LICENSE AS SPECIFIED IN THE 'LICENSE' FILE IN THIS DIRECTORY.

liipmonitor's People

Contributors

defrag avatar dmecke avatar lsmith77 avatar pborreli avatar ph3nol avatar pulse00 avatar roderik avatar shieldo avatar tomadam avatar videlalvaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

liipmonitor's Issues

DiscUsageCheck Params

Hi,

This check is not accepting any parameters. Can you explain how to pass the params.

Check Http - add SSL option

Is it possible to add an option to test https? fsockopen requires ssl:// scheme in the host parameter which should not be added in the request header.

Any technical reason for deprecation or just lack of desire to maintain?

If the latter, I don't mind to take over maintenance of it (either here as a promoted contributor/project maintainer, or on my fork of it).

Currently there appear to be features here that are not part of zenddiagnostics at all (check runner and check chain), unless I missed those during a quick glance and check.

Thanks!

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.