leankoala / healthfoundation
PHP 的可扩展健康检查框架
1.0.0
2021-04-09 13:23 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.3
- phmlabs/init: dev-master
- symfony/console: >=3.1 <6.0
- symfony/yaml: >=3.1 <6.0
- uptime/uptime: 0.2.0
Suggests
- ext-json: Used for most output formats
- ext-mysqli: Needed if database checks are used
This package is not auto-updated.
Last update: 2024-09-18 21:55:42 UTC
README
HealthCheckFoundation 是一个开源库,旨在简化为网络项目中的所有重要组件提供持续的健康状态。它被设计成非常可扩展。
使用 HealthFoundation
HealthFoundation 被设计为可以独立运行或集成到任何项目中。
示例
配置文件
此示例检查磁盘空间使用率是否小于 95%。
$ php bin/health.php run health.yml
配置文件 health.yml
可以如下所示
format: class: Leankoala\HealthFoundation\Result\Format\Ietf\IetfFormat parameters: passedMessage: "Storage server is up and running." failureMessage: "Some problems occurred on storage server." checks: spaceUsed: check: Leankoala\HealthFoundation\Check\Device\SpaceUsedCheck identifier: space_used_check description: 'Space used on storage server' parameters: maxUsageInPercent: 95
有关如何使用此功能的信息,请参阅 RunCommand
。
代码
与代码相同的检查
# health.php include_once __DIR__ . '/../vendor/autoload.php'; $foundation = new \Leankoala\HealthFoundation\HealthFoundation(); // max disc usage 95% $spaceUsedCheck = new \Leankoala\HealthFoundation\Check\Device\SpaceUsedCheck(); $spaceUsedCheck->init(95); $foundation->registerCheck( $spaceUsedCheck, 'space_used_check', 'Space used on storage server'); $runResult = $foundation->runHealthCheck(); $formatter = new \Leankoala\HealthFoundation\Result\Format\Ietf\IetfFormat( 'Storage server is up and running.', 'Some problems occurred on storage server.' ); $formatter->handle( $runResult );
检查
格式化程序
可以生成任何类型的健康检查格式。目前支持 IETF 标准(《HTTP APIs 健康检查响应格式》[https://datatracker.ietf.org/doc/draft-inadarei-api-health-check/?include_text=1]),但提供了一个简单的接口来创建新格式。
状态
已实现的健康检查
由于这是一个开源项目,我们希望每个人都能提交自己的检查,因此我们为列表中的每个检查提供了主要作者的联系方式。
- 基本
- 数字
- LessThan (nils.langner@leankoala.com)
- 数字
- 数据库
- MySQL
- 从属
- SlaveStatusField (nils.langner@leankoala.com)
- MysqlRunning (nils.langner@leankoala.com)
- 从属
- Redis
- ListLength (nils.langner@leankoala.com)
- MySQL
- 设备
- SpaceUsed (nils.langner@leankoala.com)
- Uptime (nils.langner@leankoala.com)
- Docker
- 容器
- ContainerIsRunningCheck (nils.langner@leankoala.com)
- 容器
- 文件
- 内容
- NumberOfLines (nils.langner@leankoala.com)
- FileCreatedAfter (nils.langner@leankoala.com)
- FileExists (nils.langner@leankoala.com)
- 内容
- 资源
- HTTP
- StatusCode (galenski@online-verlag-freiburg.de)
- HTTP
- 系统
- Uptime (nils.langner@leankoala.com)
- NumberProcesses (nils.langner@leankoala.com)
健康检查的想法
- 数据库
- MySQL
- 返回元素数量
- Redis
- isRunning
- MySQL
- 文件
- isWritable
- FileEditedAfter
- 工具
- Wordpress
- 插件
- 过时插件数量
- isOutdated
- isInsecure
- 插件
- Wordpress
Outlook / Ideas
- Suggestions - 工具应自动查找可以测试的内容
- Plugins - 希望有适用于 WordPress、Shopware、Symfony 等的插件/包
- History - 记住最后的健康状态
- Action - 健康检查失败后执行某些操作