akondas / symfony-actuator-bundle
为您的Symfony应用程序提供生产就绪的功能
Requires
- php: ^7.4 || ^8.0
- symfony/framework-bundle: ^5.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12.70
- phpunit/phpunit: ^9.5
- symfony/browser-kit: ^5.2
- symfony/yaml: ^5.2
This package is auto-updated.
Last update: 2024-08-30 01:23:28 UTC
README
为您的Symfony应用程序提供生产就绪的功能。Actuator端点允许您监控和与应用程序交互
功能
- REST API端点 (
/api/actuator
) - UI控制台(尚未实现)
端点
-
/health (正在开发中的
components
){ "status": "up" }
-
/info
{ "git": { "branch": "actuator", "commit": "6c01dce07274c6fddfd58610cf5fe14964689edd" }, "php": { "version": "7.4.3", "architecture": 64, "intlLocale": "en", "timezone": "Europe/Berlin", "xdebugEnabled": false, "apcuEnabled": false, "opCacheEnabled": true }, "symfony": { "version": "5.2.2", "lts": false, "environment": "dev", "endOfMaintenance": "July 2021", "endOfLife": "July 2021", "bundles": { "FrameworkBundle": "Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle", "SensioFrameworkExtraBundle": "Sensio\\Bundle\\FrameworkExtraBundle\\SensioFrameworkExtraBundle", "TwigBundle": "Symfony\\Bundle\\TwigBundle\\TwigBundle", "MonologBundle": "Symfony\\Bundle\\MonologBundle\\MonologBundle", "DoctrineBundle": "Doctrine\\Bundle\\DoctrineBundle\\DoctrineBundle", "DoctrineMigrationsBundle": "Doctrine\\Bundle\\MigrationsBundle\\DoctrineMigrationsBundle", "SecurityBundle": "Symfony\\Bundle\\SecurityBundle\\SecurityBundle", "ActuatorBundle": "Akondas\\ActuatorBundle\\ActuatorBundle" } }, "database": { "default": { "type": "stgreSQL100", "database": "app", "driver": "Symfony\\Bridge\\Doctrine\\Middleware\\Debug\\Driver" } } }
安装
composer require akondas/symfony-actuator-bundle
将 ActuatorBundle
添加到 config/bundles.php
Akondas\ActuatorBundle\ActuatorBundle::class => ['all' => true]
将 actuator.yaml
添加到 config/routes
目录(您可以更改前缀)
web_profiler_wdt: resource: '@ActuatorBundle/Resources/config/routing.yaml' prefix: /api/actuator
安全性
⚠️请注意,此包提供的信息和功能可能对您的应用程序具有潜在的危险。
使用内置的 symfony/security 组件来保护API。
以下为基本身份验证的示例配置(security.yaml
)
security: providers: in_memory: memory: users: admin: password: 'password' roles: 'ROLE_ACTUATOR' firewalls: actuator: http_basic: ~ access_control: - { path: ^/api/actuator, roles: ROLE_ACTUATOR } encoders: Symfony\Component\Security\Core\User\User: plaintext
扩展
健康指标
您可以编写自己的健康指标并实现自己的逻辑来确定应用程序的状态。为此,您必须实现接口 HealthIndicator
并将服务标记为 akondas.health_indicator
。
例如,在 src/Health/CustomHealthIndicator.php
下添加以下类
<?php declare(strict_types=1); namespace App\Health; use Akondas\Service\Health\HealthIndicator; use Akondas\Service\Health\Health; class CustomHealthIndicator implements HealthIndicator { public function name(): string { return 'custom'; } public function health(): Health { return Health::up()->setDetails(['state' => 'OK!']); } }
然后,将以下定义添加到 config/services.yaml
services: App\Health\CustomHealthIndicator: tags: ['akondas.health_indicator']
信息收集器
类似于健康指标,您还可以编写一个暴露信息的服务。为此,您必须实现接口 Collector
并添加标记 akondas.info_collector
。
<?php declare(strict_types=1); namespace App\Info; use Akondas\Service\Info\Collector\Collector; use Akondas\Service\Info\Info; class CustomInfoCollector implements Collector { public function collect(): Info { return new Info('my-info', [ 'time' => time() ]); } }
然后,将以下定义添加到 config/services.yaml
services: App\Info\CustomInfoCollector: tags: ['akondas.info_collector']
配置参考
该包默认情况下无需配置即可工作。如果需要更改默认配置,请在 config/packages/actuator.yaml
下创建配置文件。默认配置如下
actuator: health: enabled: true builtin: disk_space: enabled: true threshold: 52428800 path: '%kernel.project_dir%' database: enabled: true connections: default: service: 'Doctrine\DBAL\Connection' check_sql: 'SELECT 1' info: enabled: true builtin: php: enabled: true symfony: enabled: true git: enabled: true database: enabled: true connections: connection_name: 'Doctrine\DBAL\Connection'
以下表格概述了配置
路线图
- flex配方
- 组件的状态(数据库、邮件发送者、通知者等)
- 组件的端点
- messenger:显示失败的消息,通过消息类重试(最受欢迎的功能!)
- mailer:发送电子邮件
- cache:清除缓存?
- notifier:触发测试通知
- UI:与REST API相同,但以管理面板的美感呈现。特别是我关心messenger组件,因为目前重试错误消息非常麻烦
许可
SymfonyActuatorBundle在MIT许可下发布。有关详细信息,请参阅捆绑的LICENSE文件。