nagy/health-check
Composer 安装命令:
composer require nagy/health-check
包简介
README 文档
README
Monitor your laravel server and application health and get notified immediately.
Features
- Dashboard
- APIs
- Artisan command
- Schedule
- Notifications
- Implemented Checkers
- ProcessCount
- Expression
- ServerAvailability
- Custom Checkers
Install
$ composer require nagy/health-check
publish config files and resources
$ php artisan vendor:publish --provider='Nagy\HealthChecker\ServiceProvider'
Dashboard
http://localhost/health-check/dashboard

APIs
get all checkers: http://localhost/health-check/checkers
response:
[
'httpd-check',
'app-debug'
]
get all check results http://localhost/health-check
response:
[
[
'checkerName' => 'httpd-check',
'type' => 'success',
'message' => 'Everything is ok with the process'
],
...
]
get specific checker result http://localhost/health-check/checker-name
response:
[
'checkerName' => 'httpd-check',
'type' => 'success',
'message' => 'Everything is ok with the process'
]
Artisan Command
Schedule
Package will run peridcally in the background to check you application and server health. the frequency is being set based on the laravel frequency options
Notifications
First the package is enabled by checking notifications => [ 'enabled' => true] in the configuration file, then check if the result type is exists on notifications => 'notify_on'
The current suporrted notification channels is MailChannel, you can add your custom channel by creating a class with a notify method.
The notify method accepts a collection of results.
class CustomChannel
{
public function notify(Collection $results)
{
//
}
}
Checkers
The package shipped with two global checkers
ProcessCount
used to check the count of running process, for exampl, you need to check that at least a 10 workers are ruuning, then add a new elemet to the checkers in the configuration file
checkers => [
'app-workers' => [
'class' => '\Nagy\HealthChecker\Checkers\ProcessCount',
'options' => ['processName' => 'app-workers', 'min' => 10, max => 20]
],
]
Note The package consider the checker key as the checker name, so it's highly recommend to name avoid the spaces in the checker name.
Expression
Expression checker evalutes a Specfic expression, the evalution should be true to consider the it as healthy.
'app-debug' => [
'class' => Expression::class,
'options' => ['expression' => 'env("APP_DEBUG") == true']
]
ServerAvailability
Check if the provided host is accessable via a specific port (port is optional, default is 80)
'mysql' => [
'class' => ServerAvailability::class,
'options' => ['host' => env('DB_HOST'), 'port' => env('DB_PORT')]
]
Custom Checkers
in case you need to build your own checkers then all you need to do is creating a class that extends from AbstractBaseChecker and implements HealthCheckInterface.
then you have to implement methods check, isHealthy and getMessage
class CustomChecker extends AbstractBaseChecker implements HealthCheckInterface
{
public function check(): Result
{
if ($this->isHealthy()) {
return $this->makeHealthyResult();
} else {
return $this->makeUnHealthyResult();
// return $this->makeUnHealthyResult(Result::WARNING_STATUS);
}
}
public function isHealthy(): bool
{
return true;
}
public function getMessage(): string
{
// return your message to be attached in case of unhealthy result
}
}
nagy/health-check 适用场景与选型建议
nagy/health-check 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nagy/health-check 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nagy/health-check 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-23
