govigilant/vigilant-laravel-healthchecks

A Laravel package to integrate Vigilant healthchecks

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/govigilant/vigilant-laravel-healthchecks

dev-main 2025-11-09 21:17 UTC

This package is auto-updated.

Last update: 2025-11-09 21:17:40 UTC


README

A package to integrate Vigilant's healthchecks with Laravel.

Features

  • 🔍 Health Checks: Monitor databases, cache, queues, Redis, Horizon, scheduler, and more
  • 📊 System Metrics: Track CPU, memory, disk usage, and database size

Installation

Install the package via Composer:

composer require govigilant/vigilant-laravel-healthchecks

Configuration

Publish the configuration file:

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

This creates config/vigilant-healthchecks.php where you can customize checks and metrics.

Set the API token in your .env file:

VIGILANT_HEALTHCHECK_TOKEN=your-vigilant-api-key-here

Scheduler

This package automatically schedules a command and a job to verify if your sheduler 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.

Usage

Accessing the Health Endpoint

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

POST /api/vigilant/health

Registering Checks and Metrics

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

use Vigilant\Healthchecks\Facades\HealthCheck;
use Vigilant\Healthchecks\Checks\DatabaseCheck;
use Vigilant\Healthchecks\Checks\CacheCheck;
use Vigilant\Healthchecks\Checks\RedisCheck;
use Vigilant\Healthchecks\Checks\HorizonCheck;
use Vigilant\Healthchecks\Checks\SchedulerCheck;
use Vigilant\Healthchecks\Checks\Metrics\CpuLoadMetric;
use Vigilant\Healthchecks\Checks\Metrics\MemoryUsageMetric;
use Vigilant\Healthchecks\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

Check specific database connections, cache stores, or Redis connections:

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

public function boot(): void
{
    // Check default database connection
    HealthCheck::registerCheck(DatabaseCheck::make());

    // Check a specific database connection
    HealthCheck::registerCheck(DatabaseCheck::make()->connection('mysql'));

    // Check default cache store
    HealthCheck::registerCheck(CacheCheck::make());

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

    // Check default Redis connection
    HealthCheck::registerCheck(RedisCheck::make());

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

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
DiskSpaceCheck Monitors available disk space
DebugModeCheck Warns if debug mode is enabled in production
EnvCheck Validates environment configuration

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

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.