glesys/butler-health
Composer 安装命令:
composer require glesys/butler-health
包简介
Glesys Butler Health package.
README 文档
README
🚧 Not ready for production.
Butler Health
Laravel package for returning application "health".
Getting Started
composer require glesys/butler-health php artisan vendor:publish --provider="Butler\Health\ServiceProvider" --tag=config php artisan serve # visit http://localhost:8000/health
Route
The default route is /health and is configured at butler.health.route.
The endpoint will return data in JSON.
{
"about": {
"environment": {},
"cache": {},
"drivers": {},
"butlerHealth": {
"version": "0.1"
},
},
"checks": [
{
"name": "Database",
"slug": "database",
"group": "core",
"description": "Check all database connections.",
"runtimeInMilliseconds": 10,
"result": {
"value": 1,
"message": "Connected to all databases.",
"state": "ok"
}
}
]
}
Custom route
Set butler.health.route to a falsy value to disable the default route.
Then add your own route.
Route::get('/status', Butler\Health\Controller::class)->middleware('api');
Checks
The package comes with some checks out of the box, see checks.
Register the checks you want in butler.health.checks.
// config/butler.php return [ 'health' => [ // ... 'checks' => [ Butler\Health\Checks\Database::class, App\Health\MyCheck::class, ], ], ];
Create a check
Extend Butler\Health\Check and add it to butler.health.checks, done.
Custom about information
You can push additional "about" information.
Butler\Health\Repository::add('environment', ['operatingSystem' => php_uname('s')]); Butler\Health\Repository::add('environment', fn () => ['time' => time()]);
{
"about": {
"environment": {
"operatingSystem": "Linux",
"time": 1678100209
},
"cache": {},
"drivers": {},
"butlerHealth": {},
},
"checks": []
}
Heartbeats
Configure butler.health.heartbeat.url and butler.health.heartbeat.token to enable.
heartbeat('foo bar'); // POST http://heartbeat.localhost/foo-bar/1 heartbeat('foo baz', 5); // POST http://heartbeat.localhost/foo-baz/5
Log driver
To prevent HTTP requests in local environment, set butler.health.heartbeat.driver to "log".
Fake
Instead of faking the laravel Http client in your tests you can fake heartbeats, see example below.
public function test_something() { Heartbeat::fake(); // Assert that nothing was sent... Heartbeat::nothingSent(); // Assert a heartbeat was not sent... Heartbeat::assertNotSent('foobar'); heartbeat('foobar'); // Assert 1 heartbeat was sent... Heartbeat::assertSentCount(1); // Assert a heartbeat was sent... Heartbeat::assertSent('foobar'); }
Testing
vendor/bin/phpunit vendor/bin/pint --test
How To Contribute
Development happens at GitHub; any typical workflow using Pull Requests are welcome. In the same spirit, we use the GitHub issue tracker for all reports (regardless of the nature of the report, feature request, bugs, etc.).
All changes are supposed to be covered by unit tests, if testing is impossible or very unpractical that warrants a discussion in the comments section of the pull request.
Code standard
As the library is intended for use in Laravel applications we encourage code standard to follow upstream Laravel practices - in short that would mean PSR-2 and PSR-4.
glesys/butler-health 适用场景与选型建议
glesys/butler-health 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 glesys/butler-health 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 glesys/butler-health 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-16