prgtw / healthchecks-bundle
用于与 healthchecks.io 定时监控服务的集成套餐
0.9.1
2022-11-03 17:54 UTC
Requires
- php: ^7.0
- ext-json: *
- jms/serializer: ^1.6 || ^2.0 || ^3.0
- jms/serializer-bundle: ^1.5 || ^2.0 || ^3.0
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.5.1
- php-http/httplug: ^1.0 || ^2.0
- php-http/message-factory: ^1.0
- psr/http-message-implementation: ^1.0
- symfony/config: ^2.8 || ^3.0 || ^4.0
- symfony/console: ^2.8 || ^3.0 || ^4.0
- symfony/dependency-injection: ^2.8,>=2.8.51 || ^3.0,>=3.4.26 || ^4.1,>=4.1.12 || ^4.2,>=4.2.7
- symfony/http-kernel: ^2.8 || ^3.0 || ^4.0
- symfony/options-resolver: ^2.8 || ^3.0 || ^4.0
- symfony/process: ^2.8 || ^3.0 || ^4.0
Requires (Dev)
- guzzlehttp/psr7: ^1.4
- php-http/message: ^1.5
- php-http/mock-client: ^1.0
- roave/security-advisories: dev-master
README
此套餐能够与 healthchecks.io 集成。
待办事项
- 实现并发请求
安装
-
在您的
composer.json
中要求prgtw/healthchecks-bundle
套餐包,并更新您的依赖项。composer require prgtw/healthchecks-bundle
-
将
HealthchecksBundle
添加到您的应用程序内核中public function registerBundles() { $bundles = [ // ... new prgTW\HealthchecksBundle(), // ... ]; // ... }
配置
示例配置
healthchecks: api: clients: example: "api-key-here" timezone: "Europe/Warsaw" # default timezone to use for checks checks: simple: client: example name: "Simple hourly check" timeout: 3600 tags: [simple, all] cron: client: example name: "Cron-based check" schedule: "*/30 * * * *" timezone: UTC tags: [cron, all]
用法
$api = $container->get('healthchecks.api'); // setup checks on healthchecks.io side according to configuration $api->setup('simple'); $api->setupMany(['simple', 'cron']); // ping check(s) $api->ping('simple'); $api->pingMany(['simple', 'cron']); // pause check(s) $api->pause('simple'); $api->pauseMany(['simple', 'cron']);
在运行时提供检查数据
要在运行时提供检查数据,您必须创建自己的解析器,并且您必须配置套餐使用此解析器而不是默认解析器
例如
namespace App\Healthchecks\Resolver; use prgTW\HealthchecksBundle\Resolver\ResolverInterface; class CustomResolver implements ResolverInterface { public function resolve() { // Get the data from your source and map your array in such format: return [ 'backup_task' => [ 'name' => 'Backup task', 'schedule' => '15 2 * * *', 'client' => 'dev', 'tags' => ['backup', 'devops'], 'unique' => ['name', 'tags'], ], 'cleanup_task' => [ 'name' => 'Cleanup task', 'schedule' => '0 3 * * *', 'client' => 'dev', 'tags' => ['backup', 'devops'], 'unique' => ['name', 'tags'], ], ]; } public function resolveNames(): array { return ['backup_task', 'cleanup_task']; } }
services: healthchecks.resolver.custom: class: "App\\Healthchecks\\Resolver\\CustomResolver"
healthchecks: api: clients: example: "api-key-here" timezone: "Europe/Warsaw" # default timezone to use for checks resolver: "healthchecks.resolver.custom" #Service ID of your custom resolver