alahaxe/healthcheck-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

alahaxe/healthcheck-bundle

Composer 安装命令:

composer require alahaxe/healthcheck-bundle

包简介

Extensible healthcheck bundle for SF

README 文档

README

DeepSource Packagist PHP Version Support Packagist Version GitHub Workflow Status (branch)

This bundle allows to easily expose a healthcheck on a Symfony application. You can add as many checks you want and create your own checks.

Installation

    composer require alahaxe/healthcheck-bundle

Quickstart

1- Router

Register package routes in your application

lahaxearnaud_healthcheck:
    resource: "@HealthCheckBundle/Resources/config/router.yaml"

Default route for healthcheck is /_healthcheck

2- Firewall

Allow any requests to call the healthcheck endpoint.

security:
    firewalls:
        healthcheck:
            pattern: ^/_healthcheck
            security: false

Use custom route

Do not load resource @HealthCheckBundle/Resources/config/router.yaml file in your router but add:

lahaxearnaud_healthcheck:
    path: /my-healthcheck
    controller: Alahaxe\HealthCheckBundle\Controller\HealthCheckController

Adapte firewall pattern:

security:
    firewalls:
        healthcheck:
            pattern: ^/my-healthcheck
            security: false

Use available checks

Name Package Current version
Doctrine check alahaxe/healthcheck-doctrine Packagist Version
System check alahaxe/healthcheck-system Packagist Version
Redis check alahaxe/healthcheck-redis Packagist Version
Curl check alahaxe/healthcheck-curl Packagist Version

Add a custom check

Create a custom class that implements CheckInterface:

<?php

namespace App\Service\HealthCheck;

use Alahaxe\HealthCheckBundle\CheckStatus;
use Alahaxe\HealthCheckBundle\Contract\CheckInterface;

class AppCheck implements CheckInterface
{
    public function check(): CheckStatus
    {
        return new CheckStatus(
            'app', // the name in the final json
            __CLASS__, // only for debug
            CheckStatus::STATUS_OK, // or CheckStatus::STATUS_WARNING or CheckStatus::STATUS_INCIDENT
            'An optional message, publicly exposed',
            200 // an HTTP status
        );
    }
}

The output on /_healthcheck will be:

{
    "checks": {
        "app": {
            "payload": "An optional message, publicly exposed",
            "status": "ok"
        }
    }
}

Register the service with the tag lahaxearnaud.healthcheck.check :

    App\Service\HealthCheck\AppCheck:
        tags: ['lahaxearnaud.healthcheck.check']

Or if you have many checks you can add the tag on a folder:

    App\Service\HealthCheck\:
        resource: '../src/Service/HealthCheck'
        tags: ['lahaxearnaud.healthcheck.check']

Http verbosity

Verbosity configuration allows to redure informations exposed publicly. If your healthcheck is protected (firewall, network rules...) you should use a full configuration. Default verbosity is minimal

Full configuration

In your symfony configs:

health_check:
    http:
        format: full

Example of http response:

{
    "context": {
        "environment": "dev",
        "datetime": "2022-01-05T17:00:53+00:00"
    },
    "health": false,
    "checks": {
        "databaseConnectivity": {
            "payload": null,
            "status": "ok"
        },
        "freeSpace": {
            "payload": null,
            "status": "warning"
        },
        "cpuLoad": {
            "payload": null,
            "status": "incident"
        },
        "redis": {
            "payload": null,
            "status": "ok"
        },
        "app": {
            "payload": null,
            "status": "ok"
        }
    }
}

Minimal configuration:

In your symfony configs:

health_check:
    http:
        format: minimal

Example of http response:

{
    "health": false
}

Events / Listeners

Name When
Alahaxe\HealthCheckBundle\Event\HealthCheckAllEvent::class When all checks are tested
Alahaxe\HealthCheckBundle\Event\HealthCheckEvent::class When a check is tested

By default a log is written on each Alahaxe\HealthCheckBundle\Event\HealthCheckAllEvent::class, take a look at Alahaxe\HealthCheckBundle\Event\Subscriber\LoggerSubscriber for an example.

License

This bundle is under the MIT license. See the complete license in the bundle.

alahaxe/healthcheck-bundle 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-30