leankoala / healthfoundation
A expendable health check framework for PHP
Installs: 8 971
Dependents: 2
Suggesters: 0
Security: 0
Stars: 10
Watchers: 5
Forks: 3
Open Issues: 2
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.3
- phmlabs/init: dev-master
- symfony/console: >=3.1 <6.0
- symfony/yaml: >=3.1 <6.0
- uptime/uptime: 0.2.0
Suggests
- ext-json: Used for most output formats
- ext-mysqli: Needed if database checks are used
This package is not auto-updated.
Last update: 2024-10-30 22:32:22 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.
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.
- Basic
- Number
- LessThan (nils.langner@leankoala.com)
- Number
- Database
- MySQL
- Slave
- SlaveStatusField (nils.langner@leankoala.com)
- MysqlRunning (nils.langner@leankoala.com)
- Slave
- Redis
- ListLength (nils.langner@leankoala.com)
- MySQL
- Device
- SpaceUsed (nils.langner@leankoala.com)
- Uptime (nils.langner@leankoala.com)
- Docker
- Container
- ContainerIsRunningCheck (nils.langner@leankoala.com)
- Container
- Files
- Content
- NumberOfLines (nils.langner@leankoala.com)
- FileCreatedAfter (nils.langner@leankoala.com)
- FileExists (nils.langner@leankoala.com)
- Content
- Resource
- HTTP
- StatusCode (galenski@online-verlag-freiburg.de)
- HTTP
- System
- Uptime (nils.langner@leankoala.com)
- NumberProcesses (nils.langner@leankoala.com)
Ideas for health checks
- Database
- MySQL
- NumberOfReturnedElements
- Redis
- isRunning
- MySQL
- Files
- isWritable
- FileEditedAfter
- Tool
- Wordpress
- Plugins
- NumberOfOutdatedPlugins
- isOutdated
- isInsecure
- Plugins
- Wordpress
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