leankoala/healthfoundation

A expendable health check framework for PHP

1.0.0 2021-04-09 13:23 UTC

This package is not auto-updated.

Last update: 2024-12-11 23:15:39 UTC


README

The HealthCheckFoundation is an open source library that should make it easy to provide continuous health statuses for all important components in web projects. It was designed to be very extensible.

Scrutinizer Code Quality

Using HealthFoundation

HealthFoundation was designed to be run standalone or within any project.

Example

Config file

This example checks if the disc space is used is less than 95 percent.

$ php bin/health.php run health.yml

The config file health.yml could look like this

format:
  class: Leankoala\HealthFoundation\Result\Format\Ietf\IetfFormat
  parameters:
    passedMessage: "Storage server is up and running."
    failureMessage: "Some problems occurred on storage server."

checks:
  spaceUsed:
    check: Leankoala\HealthFoundation\Check\Device\SpaceUsedCheck
    identifier: space_used_check
    description: 'Space used on storage server'
    parameters:
      maxUsageInPercent: 95

For more information on how to use this have a look at the RunCommand.

Code

The same check as code

# health.php

include_once __DIR__ . '/../vendor/autoload.php';

$foundation = new \Leankoala\HealthFoundation\HealthFoundation();

// max disc usage 95%
$spaceUsedCheck = new \Leankoala\HealthFoundation\Check\Device\SpaceUsedCheck();
$spaceUsedCheck->init(95);

$foundation->registerCheck(
    $spaceUsedCheck, 
    'space_used_check', 
    'Space used on storage server');

$runResult = $foundation->runHealthCheck();

$formatter = new \Leankoala\HealthFoundation\Result\Format\Ietf\IetfFormat(
    'Storage server is up and running.', 
    'Some problems occurred on storage server.'
);
    
$formatter->handle(
    $runResult  
);

Checks

Formatter

It is possible to produce any kind of health check format. At the moment the IETF standard (Health Check Response Format for HTTP APIs) is supported but there is an simple interface that can be implemented to create new formats.

Status

Implemented health checks

As this is an open source project we want everybody to submit their own checks, that is why we provide the main author of every check in this list.

Ideas for health checks

  • Database
    • MySQL
      • NumberOfReturnedElements
    • Redis
      • isRunning
  • Files
    • isWritable
    • FileEditedAfter
  • Tool
    • Wordpress
      • Plugins
        • NumberOfOutdatedPlugins
      • isOutdated
      • isInsecure

Outlook / Ideas

  • Suggestions - the tool should find on its own what can be tested
  • Plugins - It would be great if there where plugins/bundles for WordPress, Shopware, Symfony etc.
  • History - Remember the last health status
  • Action - Do something after a health check fails