govigilant/laravel-healthchecks 问题修复 & 功能扩展

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

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

govigilant/laravel-healthchecks

Composer 安装命令:

composer require govigilant/laravel-healthchecks

包简介

A Laravel package to add healthchecks which can be integrated with govigilant.io

README 文档

README

Banner

Vigilant Laravel Healthchecks

Tests Analysis Style Total downloads

A package that adds healthchecks to any Laravel application and integrates seamlessly with Vigilant.

Features

This package provides an API endpoint to check the health of your Laravel application. It returns two types of checks, health checks and metrics. Healthchecks are checks that indicate whether a specific part of your application is functioning correctly, while metrics provide numeric values that give insights on health over time. Vigilant can use these metrics to notify you of spikes or quickly increasing metrics.

Installation

Install the package via Composer:

composer require govigilant/laravel-healthchecks

Configuration

Set the API token in your .env file:

VIGILANT_HEALTHCHECK_TOKEN=your-vigilant-api-key-here

Note: The token is required to access the health endpoint.

Optionally publish the configuration if you want to adjust default behavior:

php artisan vendor:publish --provider="Vigilant\LaravelHealthchecks\ServiceProvider"

This creates config/vigilant-healthchecks.php.

Scheduler

This package automatically schedules a command and a job to verify if your scheduler and queue workers are running. If you do not want or want to customize this behavior, you can disable the automatic scheduling in the config file by setting schedule to false.

Ensure to schedule the php artisan vigilant:scheduler-heartbeat yourself if you disable automatic scheduling.

Usage

Accessing the Health Endpoint

Once installed, the health check endpoint is available with your configured bearer token at:

POST /api/vigilant/health

Or using curl:

curl -X POST "YOUR_URL_HERE/api/vigilant/health" \
  -H "Authorization: Bearer YOUR_BEARER_TOKEN" \
  -H "Content-Type: application/json"

Registering Checks and Metrics

Register health checks and metrics in your AppServiceProvider's boot method.

Note: The package comes with defaults, so you may not need to register any checks or metrics manually when having the register setting enabled in the config file.

use Vigilant\LaravelHealthchecks\Facades\HealthCheck;
use Vigilant\LaravelHealthchecks\Checks\DatabaseCheck;
use Vigilant\LaravelHealthchecks\Checks\CacheCheck;
use Vigilant\LaravelHealthchecks\Checks\RedisCheck;
use Vigilant\LaravelHealthchecks\Checks\HorizonCheck;
use Vigilant\LaravelHealthchecks\Checks\SchedulerCheck;
use Vigilant\LaravelHealthchecks\Checks\Metrics\CpuLoadMetric;
use Vigilant\LaravelHealthchecks\Checks\Metrics\MemoryUsageMetric;
use Vigilant\LaravelHealthchecks\Checks\Metrics\DiskUsageMetric;

public function boot(): void
{
    HealthCheck::registerCheck(DatabaseCheck::make());
    HealthCheck::registerCheck(CacheCheck::make());
    HealthCheck::registerCheck(RedisCheck::make());
    HealthCheck::registerCheck(HorizonCheck::make());
    HealthCheck::registerCheck(SchedulerCheck::make());

    HealthCheck::registerMetric(CpuLoadMetric::make());
    HealthCheck::registerMetric(MemoryUsageMetric::make());
    HealthCheck::registerMetric(DiskUsageMetric::make());
}

Configuring Specific Connections

If you want to check non-default connections you can register healthchecks yourself in your service provider.

use Vigilant\LaravelHealthchecks\Facades\HealthCheck;
use Vigilant\LaravelHealthchecks\Checks\DatabaseCheck;
use Vigilant\LaravelHealthchecks\Checks\CacheCheck;
use Vigilant\LaravelHealthchecks\Checks\RedisCheck;

public function boot(): void
{
    // Check a specific database connection
    HealthCheck::registerCheck(DatabaseCheck::make()->connection('mysql'));

    // Check a specific cache store
    HealthCheck::registerCheck(CacheCheck::make()->store('redis'));

    // Check a specific Redis connection
    HealthCheck::registerCheck(RedisCheck::make()->connection('sessions'));
}

Check availability

Each healthcheck checks if it is applicable in the current environment. For example, the HorizonCheck will only run if Laravel Horizon is installed. If a check is not applicable, it will be skipped and not included in the results. You may override this behaviour by registering the check manually can calling the alwaysRun method.

Available Checks

Check Description
DatabaseCheck Verifies database connection and query execution
CacheCheck Tests cache read/write operations
RedisCheck Verifies Redis connection health
RedisMemoryCheck Monitors Redis max memory usage
QueueCheck Checks queue workers are processing jobs
HorizonCheck Verifies Laravel Horizon is running
SchedulerCheck Ensures Laravel scheduler is active
StorageCheck Validates storage directory permissions
DebugModeCheck Warns if debug mode is enabled in production

Available Metrics

Metric Description
CpuLoadMetric Current CPU load average
MemoryUsageMetric System memory usage percentage
DiskUsageMetric Disk space usage percentage
DatabaseSizeMetric Total database size
LogFileSizeMetric Laravel log file size

Development Environment

A ready-to-use Docker-based development environment lives in devenv/. Ensure Docker is running, then start the stack: docker compose -f devenv/docker-compose.yml up --build.

This will create a Laravel application, link this package for development, and set the bearer token to testing, which can be used to access the health endpoint:

curl -X POST "http://localhost:8000/api/vigilant/health" \
  -H "Authorization: Bearer testing" \
  -H "Content-Type: application/json"

Quality

Run the quality checks:

composer quality

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

govigilant/laravel-healthchecks 适用场景与选型建议

govigilant/laravel-healthchecks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 578 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 govigilant/laravel-healthchecks 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-30