rob-lester-jr04/laravel-health-expansion

An expansion pack for Spatie Laravel Health package

1.0.1 2024-06-25 15:13 UTC

This package is auto-updated.

Last update: 2024-10-25 15:54:49 UTC


README

Latest Version on Packagist PHP Composer Total Downloads

Using this package to add more health checks to Spatie Health Checks for Laravel.

Installation

composer require rob-lester-jr04/laravel-health-expansion

Laravel will automatically register the service provider.

Here's an example where we'll monitor errors in PaperTrail.

// typically, in a service provider

use Spatie\Health\Facades\Health;
use Lester\Health\Checks\Checks\PaperTrailCheck;

Health::checks([
	PaperTrailCheck::new()
		->onSystem('my-system-1'),
]);

By default, this will report a failure if there are more than 20 errors in the default time frame (10 minutes). It will report a warning if there are more than 10, and it will report as ok if the error count is under 10. The thresholds can be changed with the following methods:

...highCount();
...lowCount();

// Change time frame (in minutes)
...lastMinutes();

Available Checks

This package also contains the following checks:

  • MailgunDomainCheck
    • This check will get the status for your mailgun domain(s) so you can monitor if mailgun has flagged your deliverability.
  • ApiCheck
    • This check allows you to get the laravel health from another application. Useful for creating a permenant dashboard screen that monitors all your other systems.
  • PaperTrailCheck
    • Scans PaperTrail logs for a set number of errors in a set time frame.

Using the MailGun domain check

First, set the API key in the .env file.

	MAILGUN_SECRET=########

Then enable the check in the service provider

use Spatie\Health\Facades\Health;
use Lester\Health\Checks\Checks\MailgunDomainCheck;

Health::checks([
	// ...
	
	MailgunDomainCheck::new()
		->domain('mg.example.com'),
		
	// ...
]);

Testing

composer test