alahaxe/healthcheck-bundle
最新稳定版本:v2.0.2
Composer 安装命令:
composer require alahaxe/healthcheck-bundle
包简介
Extensible healthcheck bundle for SF
README 文档
README
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.
Installation
composer require alahaxe/healthcheck-bundle
Quickstart
1- Router
Register package routes in your application
lahaxearnaud_healthcheck: resource: "@HealthCheckBundle/Resources/config/router.yaml"
Default route for healthcheck is /_healthcheck
2- Firewall
Allow any requests to call the healthcheck endpoint.
security: firewalls: healthcheck: pattern: ^/_healthcheck security: false
Use custom route
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
Use available checks
| Name | Package | Current version |
|---|---|---|
| Doctrine check | alahaxe/healthcheck-doctrine | |
| System check | alahaxe/healthcheck-system | |
| Redis check | alahaxe/healthcheck-redis | |
| Curl check | alahaxe/healthcheck-curl |
Add a custom check
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']
Http verbosity
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
Full configuration
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"
}
}
}
Minimal configuration:
In your symfony configs:
health_check: http: format: minimal
Example of http response:
{
"health": false
}
Events / Listeners
| 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.
License
This bundle is under the MIT license. See the complete license in the bundle.
统计信息
- 总下载量: 9.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-30