承接 symsensor/actuator-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

symsensor/actuator-bundle

Composer 安装命令:

composer require symsensor/actuator-bundle

包简介

Extensible bundle to provide runtime health or information about a deployed application

关键字:

README 文档

README

ActuatorBundle provides basically two features:

  • It provides an endpoint which can be used as a health probe url
  • With another endpoint you can read runtime informations about the deployed software

It is also easily extensible, so you add your custom logic to both features. Some predefined extensions can be also found within this GitHub organization.

The bundle is heavily inspired by akondas/symfony-actuator-bundle.

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require symsensor/actuator-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require symsensor/actuator-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    SymSensor\ActuatorBundle\SymSensorActuatorBundle::class => ['all' => true],
];

After the installation you have to configure the routing in your config/routes.yaml file:

actuator:
  resource: '@SymSensorActuatorBundle/config/routing.yaml'
  prefix: /_actuator

The routing defines two endpoints:

  • <prefix>/health
  • <prefix>/info

You should secure the two endpoints with the builtin Security so that the two endpoints are not public accessible.

Configuration

The Bundle can be configured with a configuration file named config/packages/sym_sensor_actuator.yaml. Following snippet shows the default value for all configurations:

sym_sensor_actuator:
  health:
    enabled: true
    builtin:
      disk_space:
        enabled: true
        threshold: 52428800
        path: '%kernel.project_dir%'
  info:
    enabled: true
    builtin:
      php:
        enabled: true
      symfony:
        enabled: true
      git:
        enabled: true

Following table outlines the configuration:

key default description
sym_sensor_actuator.health.enabled true if the health endpoint should be enabled
sym_sensor_actuator.health.disk_space.enabled true if the builtin disk_space health endpoint should be enabled
sym_sensor_actuator.health.disk_space.threshold 52428800 Size in bytes which has to be free in order that this health endpoint is "UP"
sym_sensor_actuator.health.disk_space.path '%kernel.project_dir%' The directory which should be monitored
sym_sensor_actuator.info.enabled true if the info endpoint should be enabled
sym_sensor_actuator.info.builtin.php.enabled true if the php info endpoint should be enabled
sym_sensor_actuator.info.builtin.symfony.enabled true if the symfony info endpoint should be enabled
sym_sensor_actuator.info.builtin.git.enabled true if the git info endpoint should be enabled

Extending

Health indicator

You can write your own health indicator and implement your own logic to determine the state of your application. To do so, you have to implement the interface HealthIndicator and tag your service with the tag sym_sensor_actuator.health_indicator.

So for example, add following class under src/Health/CustomHealthIndicator.php:

<?php

declare(strict_types=1);

namespace App\Health;

use SymSensor\ActuatorBundle\Service\Health\HealthIndicator;
use SymSensor\ActuatorBundle\Service\Health\Health;

class CustomHealthIndicator implements HealthIndicator
{
    public function name(): string
    {
        return 'custom';
    }

    public function health(): Health
    { 
        return Health::up()->setDetails(['state' => 'OK!']);
    }
}

Then add following definition to config/services.yaml:

services:
  App\Health\CustomHealthIndicator: 
    tags: ['sym_sensor_actuator.health_indicator']

Information Collector

Similar to a health indicator, you can write also a service which exposes informations. To do so, you have to implement the interface Collector and add the tag sym_sensor_actuator.info_collector.

<?php

declare(strict_types=1);

namespace App\Info;

use SymSensor\ActuatorBundle\Service\Info\Collector\Collector;
use SymSensor\ActuatorBundle\Service\Info\Info;

class CustomInfoCollector implements Collector
{
    public function collect(): Info
    {
        return new Info('my-info', [ 'time' => time() ]);
    }
}

Then add following definition to config/services.yaml:

services:
  App\Info\CustomInfoCollector: 
    tags: ['sym_sensor_actuator.info_collector']

License

ActuatorBundle is released under the MIT Licence. See the bundled LICENSE file for details.

Author

Originally developed by Arkadiusz Kondas

symsensor/actuator-bundle 适用场景与选型建议

symsensor/actuator-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.5k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「actuator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 symsensor/actuator-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 symsensor/actuator-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 symsensor/actuator-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 18.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 28
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-08