定制 glesys/butler-health 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

glesys/butler-health

最新稳定版本:v0.6.3

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.

统计信息

  • 总下载量: 18.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 9
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04