spatie/laravel-health
Monitor your Laravel app’s health by registering checks (disk space, etc.) with warning/fail thresholds. Get notified via mail or Slack when checks degrade, and extend with custom checks for proactive alerting.
This check makes sure your database doesn't have too much active connections. This check supports MySQL and Postgres.
If there are more than 50 connections, this check will fail. Of course, you can customize that amount.
You'll need to install the doctrine/dbal package in your project.
composer require doctrine/dbal
Here's how you can register the check, and let if fail when there are more than 100 connections.
use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\DatabaseConnectionCountCheck;
Health::checks([
DatabaseConnectionCountCheck::new()
->failWhenMoreConnectionsThan(100)
]);
Optionally, you can also specify a warning threshold.
use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\DatabaseConnectionCountCheck;
Health::checks([
DatabaseConnectionCountCheck::new()
->warnWhenMoreConnectionsThan(50)
->failWhenMoreConnectionsThan(100)
]);
To check another database connection, call connectionName()
DatabaseConnectionCountCheck::new()->connectionName('another-connection-name'),
How can I help you explore Laravel packages today?