PHPackages                             newyear/plugins-health - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. newyear/plugins-health

ActiveLibrary

newyear/plugins-health
======================

可插拔健康检查模块，支持 HTTP、MySQL、Redis、OSS/S3 等依赖检测与告警

1.0.0(11mo ago)01MITPHPPHP &gt;=8.0

Since May 30Pushed 11mo agoCompare

[ Source](https://github.com/znewyear/plugins-health)[ Packagist](https://packagist.org/packages/newyear/plugins-health)[ RSS](/packages/newyear-plugins-health/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (3)Used By (0)

plugins-health 健康检查插件
=====================

[](#plugins-health-健康检查插件)

项目简介
----

[](#项目简介)

本项目为企业级 PHP 健康检查插件，支持 Lumen/Laravel/Laminas/Webman 等主流框架，核心无依赖、适配层解耦，支持 HTTP、MySQL、Redis、OSS/S3 等依赖检测、分级告警、事件通知、接口自动扫描、调用日志、命令行工具等功能。适用于微服务、SaaS、企业后台等多场景健康监控。

---

配置项说明
-----

[](#配置项说明)

`config/health.php` 示例：

```
return [
    'enabled' => true,
    'services' => [
        [
            'check' => \Health\Core\Health::MYSQL,
            'name' => 'mysql',
            'host' => '127.0.0.1',
            'port' => 3306,
            'database' => 'test',
            'username' => 'root',
            'password' => '',
            'require' => \Health\Core\Health::REQUIRE_CRITICAL, // 依赖级别
            'timeout' => 2,
            // 'event' => MyHealthEvent::class, // 可选，事件类名
        ],
        [
            'check' => \Health\Core\Health::REDIS,
            'name' => 'redis',
            'host' => '127.0.0.1',
            'port' => 6379,
            'require' => \Health\Core\Health::REQUIRE_REQUIRED,
            'timeout' => 2,
        ],
        [
            'check' => \Health\Core\Health::HTTP,
            'name' => 'external-api',
            'url' => 'https://api.example.com/health',
            'method' => 'GET',
            'timeout' => 3,
            'require' => \Health\Core\Health::REQUIRE_OPTIONAL,
        ],
        // ...
    ],
    'log' => [
        'table' => 'health_call_logs',
        'retention_days' => 30,
    ],
    // 全局事件（可选）
    // 'event' => MyHealthEvent::class,
];
```

### 依赖级别常量

[](#依赖级别常量)

- `Health::REQUIRE_CRITICAL`：系统核心依赖
- `Health::REQUIRE_REQUIRED`：业务主流程依赖（默认）
- `Health::REQUIRE_OPTIONAL`：可选依赖
- `Health::REQUIRE_EXTERNAL`：外部第三方依赖

### 事件机制

[](#事件机制)

- 实现 `HealthEventInterface`，如： ```
    class MyHealthEvent implements HealthEventInterface {
        public function success($status) { ... }
        public function wrong($status) { ... }
        public function error($status) { ... }
        public function danger($status) { ... }
    }
    ```
- 配置项可全局或单项指定 'event' =&gt; MyHealthEvent::class

---

核心实现逻辑
------

[](#核心实现逻辑)

- **解耦架构**：核心逻辑（Orchestrator/Checker/Inspection/HealthStatus）无框架依赖，适配层负责注册、路由、命令等集成。
- **Checker**：每种依赖类型实现独立 Checker，支持 PDO/Redis/Predis/HTTP/OSS 等多种方式。
- **Orchestrator**：统一调度所有检查项，支持批量/单项检查、超时、分级、事件通知。
- **事件机制**：支持 success/wrong/error/danger 四种事件，自动分派，便于自定义告警、日志、通知等。
- **接口自动扫描**：各框架适配层均支持路由自动扫描，支持 controller/action 拆分、全局/路由中间件展示。
- **命令行工具**：各框架均有 health:check、health:routes 命令，便于运维和自动化。

---

Lumen 项目集成与使用
-------------

[](#lumen-项目集成与使用)

### 1. 安装

[](#1-安装)

- 安装依赖：

```
composer require newyear/plugins-health
```

### 2. 注册服务与配置

[](#2-注册服务与配置)

- 在 `bootstrap/app.php` 添加： ```
    $app->register(Health\Bridge\Lumen\HealthServiceProvider::class);
    $app->configure('health');
    // 可选：注册日志中间件
    $app->middleware([
        Health\Bridge\Lumen\HealthLogMiddleware::class,
    ]);
    ```

### 3. 路由自动注册

[](#3-路由自动注册)

- HealthServiceProvider 已自动注册 /health/status、/health/logs、/health/routes 路由，无需手动 require 路由文件。

### 4. 配置 health.php

[](#4-配置-healthphp)

- 编辑 `config/health.php`，按需添加服务项、依赖级别、事件等。

### 5. 运行/访问

[](#5-运行访问)

- 访问 `/health/status` 查看健康检查结果。
- 访问 `/health/routes` 查看所有接口列表。
- 运行 `php artisan health:check` 检查所有依赖。
- 运行 `php artisan health:routes` 列出所有路由。

### 6. 日志与事件

[](#6-日志与事件)

- 检查日志自动落库到 `health_call_logs` 表（需执行 migration）。
- 事件机制支持全局和单项自定义，便于分级告警和业务扩展。

---

典型用例与扩展
-------

[](#典型用例与扩展)

- 支持多环境/多服务健康检查，适用于微服务、SaaS、企业后台等场景。
- 可扩展自定义 Checker、事件、告警、日志等。
- 支持多框架适配，核心逻辑完全解耦，便于维护和二次开发。

---

生产环境安装说明
--------

[](#生产环境安装说明)

- 推荐通过公司自建 GitLab/VCS 仓库集成，无需发布到 Packagist。
- 生产环境只需 require 必要依赖，开发/测试时可 require-dev 所有适配层依赖。
- 详细安装方式见上文。

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance50

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

354d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/084d57a099caa10ab8f1a7713151e578d8eea148a7fd2cfaa691f5866c32b5ad?d=identicon)[NewYear](/maintainers/NewYear)

---

Top Contributors

[![znewyear](https://avatars.githubusercontent.com/u/20437766?v=4)](https://github.com/znewyear "znewyear (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/newyear-plugins-health/health.svg)

```
[![Health](https://phpackages.com/badges/newyear-plugins-health/health.svg)](https://phpackages.com/packages/newyear-plugins-health)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[genealabs/laravel-model-caching

Automatic caching for Eloquent models.

2.4k4.8M26](/packages/genealabs-laravel-model-caching)[mikebronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k127.1k1](/packages/mikebronner-laravel-model-caching)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
