This bundle allows to easily expose a healthcheck on a Symfony application. You can add as many checks you want and create your own checks.
composer require alahaxe/healthcheck-bundle
Register package routes in your application
lahaxearnaud_healthcheck:
resource: "@HealthCheckBundle/Resources/config/router.yaml"
Default route for healthcheck is /_healthcheck
Allow any requests to call the healthcheck endpoint.
security:
firewalls:
healthcheck:
pattern: ^/_healthcheck
security: false
Do not load resource @HealthCheckBundle/Resources/config/router.yaml
file in your router but add:
lahaxearnaud_healthcheck:
path: /my-healthcheck
controller: Alahaxe\HealthCheckBundle\Controller\HealthCheckController
Adapte firewall pattern:
security:
firewalls:
healthcheck:
pattern: ^/my-healthcheck
security: false
Name | Package | Current version |
---|---|---|
Doctrine check | alahaxe/healthcheck-doctrine | |
System check | alahaxe/healthcheck-system | |
Redis check | alahaxe/healthcheck-redis | |
Curl check | alahaxe/healthcheck-curl |
Create a custom class that implements CheckInterface
:
<?php
namespace App\Service\HealthCheck;
use Alahaxe\HealthCheckBundle\CheckStatus;
use Alahaxe\HealthCheckBundle\Contract\CheckInterface;
class AppCheck implements CheckInterface
{
public function check(): CheckStatus
{
return new CheckStatus(
'app', // the name in the final json
__CLASS__, // only for debug
CheckStatus::STATUS_OK, // or CheckStatus::STATUS_WARNING or CheckStatus::STATUS_INCIDENT
'An optional message, publicly exposed',
200 // an HTTP status
);
}
}
The output on /_healthcheck
will be:
{
"checks": {
"app": {
"payload": "An optional message, publicly exposed",
"status": "ok"
}
}
}
Register the service with the tag lahaxearnaud.healthcheck.check
:
App\Service\HealthCheck\AppCheck:
tags: ['lahaxearnaud.healthcheck.check']
Or if you have many checks you can add the tag on a folder:
App\Service\HealthCheck\:
resource: '../src/Service/HealthCheck'
tags: ['lahaxearnaud.healthcheck.check']
Verbosity configuration allows to redure informations exposed publicly.
If your healthcheck is protected (firewall, network rules...) you should use a full configuration.
Default verbosity is minimal
In your symfony configs:
health_check:
http:
format: full
Example of http response:
{
"context": {
"environment": "dev",
"datetime": "2022-01-05T17:00:53+00:00"
},
"health": false,
"checks": {
"databaseConnectivity": {
"payload": null,
"status": "ok"
},
"freeSpace": {
"payload": null,
"status": "warning"
},
"cpuLoad": {
"payload": null,
"status": "incident"
},
"redis": {
"payload": null,
"status": "ok"
},
"app": {
"payload": null,
"status": "ok"
}
}
}
In your symfony configs:
health_check:
http:
format: minimal
Example of http response:
{
"health": false
}
Name | When |
---|---|
Alahaxe\HealthCheckBundle\Event\HealthCheckAllEvent::class |
When all checks are tested |
Alahaxe\HealthCheckBundle\Event\HealthCheckEvent::class |
When a check is tested |
By default a log is written on each Alahaxe\HealthCheckBundle\Event\HealthCheckAllEvent::class
, take a look at Alahaxe\HealthCheckBundle\Event\Subscriber\LoggerSubscriber
for an example.
This bundle is under the MIT license. See the complete license in the bundle.