cego / service-health-checking
一个包含通用健康检查端点的包,设计时考虑到扩展性
1.1.0
2024-03-15 09:23 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- illuminate/http: ^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- cego/php-cs-fixer: ^2.0.0
- cego/phpstan: ^2.0.0
- cego/request-insurance: ^1.0.0
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^11.0
- dev-main
- 1.1.0
- 1.0.0
- 0.6.0
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- dev-renovate/configure
- dev-thwo/guzzle-security-vulnerability
- dev-nbj/prepare-for-laravel-10
- dev-thwo/randomize-cache-check-key
- dev-thwo/more-informative-about-ri-thresholds
- dev-thwo/handle-exceptions
- dev-set-active-limit-1k
- dev-niza/bump-package-versions-to-laravel9
- dev-thwo/use-config-facade
- dev-thwo/merge-config
This package is auto-updated.
Last update: 2024-09-15 10:23:59 UTC
README
此包包含用于Laravel服务HTTP健康检查的核心功能。
使用方法
当包安装后,将暴露一个健康端点 /vendor/service-health-checking
。该端点返回 200 OK
以及一个包含以下格式的JSON数据对象的身体
{ "status": "pass|warn|fail", "checks": [ { "status": "pass|warn|fail", "name": "HealthCheckClassName", "description": "Description defined in the health check class", "message": "Message set in the HealthStatus object" } ] }
checks
数组包含每个已注册健康检查的条目。
创建健康检查
要为您的服务创建一个健康检查,只需创建一个继承自 \Cego\ServiceHealthChecking\BaseHealthCheck
的类。基础方法有两个抽象方法
check(): HealthStatus
应执行检查并返回一个HealthStatus
对象。getDescription(): string
应返回健康检查的描述。
注册健康检查
首先,通过运行以下命令发布包资源
php artisan vendor:publish --provider="Cego\ServiceHealthChecking\ServiceHealthCheckingServiceProvider"
该包将发布一个配置文件 service-health-checking.php
,其中必须注册健康检查类,以便它们能够运行。该包附带一个基本的数据库连接检查,默认已注册。