fivelab/diagnostic
Composer 安装命令:
composer require fivelab/diagnostic
包简介
The library for diagnostic application.
README 文档
README
#StandWithUkraineDiagnostic
The library for diagnostic application.
Why?
This library helps for developers and devops for setup any applications.
If developer correct configure all diagnostics (paths, services, etc...) the devops before run the instance with our application only run diagnostic and can sees all problems (if it exist).
Primary problem:
The developer can add any parameter or service to application. As an example - add redis service for use in runtime. And lost provide this information before release application. The devops (or developer) release new version application and the system not have any problems. But, we have a major issue because the redis only used in runtime and not processed in deploy process.
Devops add this instance to load balancer (if exist), and in next times the application not correct work ;(
Solution:
Before add the instance to load balancer (or processed scope), devops run diagnostic and can see all major problems.
Restrictions
If you want work with this mechanism you MUST add diagnostic check to all end points. As an example:
- Are you use cache? You MUST add check for verify access to cache directory.
- Are you use logs? You MUST add check for verify access to logs directory.
- Are you use DB? You MUST add check for connect to Database.
- Are you use Redis? You MUST add check for connect to Redis.
- Are you use any client for connect via HTTP? You MUST add check for connect to this endpoint.
- etc...
Attention: the devops (infrastructure team, release manager, developer) is not magic person and cannot see all required services by sky stars.
Configure and Run
For easy configure the diagnostic, you can use \FiveLab\Component\Diagnostic\Check\Definition\DefinitionCollectionBuilder:
<?php declare(strict_types = 1); namespace Example; use FiveLab\Component\Diagnostic\Check\Definition\CheckDefinitionsBuilder; use FiveLab\Component\Diagnostic\Check\Definition\Filter\CheckDefinitionsInGroupFilter; use FiveLab\Component\Diagnostic\Check\Definition\Filter\OrXFilter; use FiveLab\Component\Diagnostic\Check\PathReadableCheck; use FiveLab\Component\Diagnostic\Check\PathWritableCheck; use FiveLab\Component\Diagnostic\Runner\Runner; $builder = new CheckDefinitionsBuilder(); $builder->addCheck('cache_dir', new PathWritableCheck('./var/cache'), 'system_dir'); $builder->addCheck('logs_dir', new PathWritableCheck('./var/logs'), 'system_dir'); $builder->addCheck('shared_dir', new PathWritableCheck('./var/shared'), 'shared_dir'); $builder->addCheck('shared_efs', new PathReadableCheck('./var/shared/.efs'), 'shared_dir'); $builder->addCheck('tmp_dir', new PathWritableCheck('./var/tmp'), ['tmp_dir', 'system_dir']); $definitions = $builder->build(); $runner = new Runner(); // Run all checks $success = $runner->run($definitions); // Run only for system dirs $definitions = $definitions->filter(new CheckDefinitionsInGroupFilter('system_dir')); $success = $runner->run($definitions); // Run tmp dir and shared dir $definitions = $definitions->filter(new OrXFilter( new CheckDefinitionsInGroupFilter('tmp_dir'), new CheckDefinitionsInGroupFilter('shared_dir') )); $success = $runner->run($definitions);
Integrate with applications
Dependency Injection
You can easily integrate this library to Symfony application, or application with DependencyInjection support.
For integrate, you can add the compiler pass to your container builder:
<?php namespace Example; use Symfony\Component\DependencyInjection\ContainerBuilder; use FiveLab\Component\Diagnostic\DependencyInjection\AddDiagnosticToBuilderCheckPass; $containerBuilder = new ContainerBuilder(); $containerBuilder->addCompilerPass(new AddDiagnosticToBuilderCheckPass()); $containerBuilder->compile();
And add check services:
services: diagnostic.check.cache_dir: class: \FiveLab\Component\Diagnostic\Check\PathWritableCheck arguments: [ '%kernel.cache_dir%' ] tags: - { name: diagnostic.check } diagnostic.check.logs_dir: class: \FiveLab\Component\Diagnostic\Check\PathWritableCheck arguments: [ '%kernel.logs_dir%' ] tags: - { name: diagnostic.check }
The tag diagnostic.check support next attributes:
- key - the unique key of check (default is service name).
- group - the group of this check (default is null).
- error_on_failure - if false, system not return error code from process (ignore failures, default is true).
Console commands
We provide console commands for easy integrate to any applications:
\FiveLab\Component\Diagnostic\Command\RunDiagnosticCommand- command for run diagnostic.\FiveLab\Component\Diagnostic\Command\ListChecksCommand- command for list all available checks.\FiveLab\Component\Diagnostic\Command\ListGroupsCommand- command for list all available groups.
Development
For easy development you can use the Docker and Docker compose.
docker compose up
docker compose exec diagnostic bash
After success run and attach to container you must install vendors:
composer install
Before create the PR or merge into develop, please run next commands for validate code:
./bin/phpunit ./bin/phpcs --config-set show_warnings 0 ./bin/phpcs --standard=src/phpcs-ruleset.xml src/ ./bin/phpcs --standard=tests/phpcs-ruleset.xml tests/ php -d memory_limit=-1 ./bin/phpstan
fivelab/diagnostic 适用场景与选型建议
fivelab/diagnostic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33.08k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「check」 「health」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fivelab/diagnostic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fivelab/diagnostic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fivelab/diagnostic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
Is your Laravel app OK? Health checks running in production to ensure you can sleep well at night and be sure everything is still OK.
Provides healthcheck endpoints in accordance with IETF's healthcheck draft RFC
Provide status and health api endpoints
SoftWax Health Check Bundle for Symfony framework
统计信息
- 总下载量: 33.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-10-23