svilborg / laravel-health
Laravel Health Check
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 13
Type:project
Requires
- laravel/framework: 5.*
Requires (Dev)
- guzzlehttp/guzzle: ^6.3
- mockery/mockery: ^1.2
- orchestra/testbench: ~3.0
- phan/phan: ^2.2
- phpunit/phpunit: ^7.0
- predis/predis: ^1.1
- solarium/solarium: ^5.0
- squizlabs/php_codesniffer: ^3.4
- symfony/yaml: ~3.4|~4.0
Suggests
- guzzlehttp/guzzle: ^6.3
- symfony/yaml: ~3.4|~4.0
- dev-master
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.0
- v0.1.0
- dev-dependabot/composer/symfony/yaml-5.3.6
- dev-dependabot/composer/phpunit/phpunit-8.5.19
- dev-dependabot/composer/solarium/solarium-6.1.4
- dev-dependabot/composer/symfony/http-kernel-4.4.29
- dev-dependabot/composer/symfony/http-foundation-4.4.29
- dev-dependabot/composer/phan/phan-4.0.7
- dev-dependabot/composer/league/flysystem-1.1.4
- dev-dependabot/composer/squizlabs/php_codesniffer-3.6.0
- dev-dependabot/composer/guzzlehttp/guzzle-7.3.0
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/mockery/mockery-1.4.3
- dev-dependabot/composer/orchestra/testbench-3.8.6
- dev-dependabot/composer/laravel/framework-5.8.38
This package is auto-updated.
Last update: 2024-11-29 05:51:36 UTC
README
Implementation of MicroProfile Health for Laravel
Configuration
Register the health check classes in config/health.php
return [ /* * |-------------------------------------------------------------------------- * | Health Checks * |-------------------------------------------------------------------------- * | */ 'checks' => [ [ 'class' => \Health\Checks\NullCheck::class, 'params' => [] ], [ 'class' => \Health\Checks\Servers\Database::class, 'params' => [] ], [ 'class' => \Health\Checks\Filesystem\DiskSpace::class, 'params' => [ 'path' => '/' ] ], [ 'class' => \Health\Checks\Env\Environment::class, 'params' => [ 'APP_ENV' => 'testing' ] ] ] ];
Add the api route
Route::get('/health', 'Health\Controllers\HealthController@check');
Example Response Payload
{ "status": "UP", "checks": [ { "name": "health-checks-null-check", "status": "UP", "data": [] }, { "name": "health-checks-filesystem-disk-space", "status": "UP", "data": { "free_bytes": 119100669952, "free_human": "110.92 GB", "path": "/", "threshold": 100000000 } }, { "name": "health-checks-env-environment", "status": "UP", "data": { "variable": "APP_ENV", "value": "testing", "value_expected": "testing" } }, { "name": "health-checks-filesystem-directory-is-readable", "status": "UP", "data": { "paths": [ "../tests" ] } }, { "name": "health-checks-filesystem-file-is-readable", "status": "UP", "data": { "files": [ "TestCase.php" ] } } ] }
Custom Health Check
use Health\Checks\BaseCheck; use Health\Checks\HealthCheckInterface; class ServiceACheck extends BaseCheck implements HealthCheckInterface { /** * * {@inheritdoc} * @see \Health\Checks\HealthCheckInterface::call() */ public function call() { $health = $this->getBuilder('Service A'); if(!$this->serviceA->connect()) { $health->withData('error', 'Service A Failed') ->down(); } else { $health->up(); } return $health->build(); } }
Health Check Cli Command
$ php artisan health
✔ UP Health State
==============================
✔ UP health-checks-null-check
✔ UP health-checks-filesystem-disk-space {"free_bytes":119302803456,"free_human":"111.11 TB","path":"\/tmp","threshold":100000000}
✔ UP health-checks-env-environment {"variable":"APP_ENV","value":"testing","value_expected":"testing"}
✔ UP health-checks-filesystem-directory-is-readable {"paths":[".\/tests"]}
✔ UP health-checks-filesystem-file-is-readable {"files":[".\/tests\/TestCase.php"]}