Skip to content

Commit

Permalink
feature(health): add healthchecking in the application
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Malusev <[email protected]>
  • Loading branch information
Dusan Malusev committed Jan 8, 2025
1 parent eaa266e commit f973441
Show file tree
Hide file tree
Showing 17 changed files with 1,159 additions and 307 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ REDIS_LOCKS_URL=tcp://redis:6379?database=0
REDIS_SESSIONS_URL=tcp://redis:6379?database=0
REDIS_PULSE_URL=tcp://redis:6379?database=0
REDIS_BROADCASTING_URL=tcp://redis:6379?database=0
REDIS_HEALTHCHECK_URL=tcp://redis:6379?database=0

REDIS_PREFIX=website

Expand Down
724 changes: 428 additions & 296 deletions .phpstorm.meta.php

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions _ide_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24281,6 +24281,85 @@ public static function originalMethod()
}
}

namespace Spatie\Health\Facades {
/**
*
*
* @mixin \Spatie\Health\Health
*/
class Health {
/**
*
*
* @param array<int, Check> $checks
* @static
*/
public static function checks($checks)
{
/** @var \Spatie\Health\Health $instance */
return $instance->checks($checks);
}

/**
*
*
* @static
*/
public static function clearChecks()
{
/** @var \Spatie\Health\Health $instance */
return $instance->clearChecks();
}

/**
*
*
* @return Collection<int, Check>
* @static
*/
public static function registeredChecks()
{
/** @var \Spatie\Health\Health $instance */
return $instance->registeredChecks();
}

/**
*
*
* @return Collection<int, ResultStore>
* @static
*/
public static function resultStores()
{
/** @var \Spatie\Health\Health $instance */
return $instance->resultStores();
}

/**
*
*
* @static
*/
public static function inlineStylesheet($stylesheet)
{
/** @var \Spatie\Health\Health $instance */
return $instance->inlineStylesheet($stylesheet);
}

/**
*
*
* @static
*/
public static function assets()
{
/** @var \Spatie\Health\Health $instance */
return $instance->assets();
}

}
}

namespace Spatie\LaravelIgnition\Facades {
/**
*
Expand Down Expand Up @@ -33744,6 +33823,7 @@ class Horizon extends \Laravel\Horizon\Horizon {}
class Octane extends \Laravel\Octane\Facades\Octane {}
class Pulse extends \Laravel\Pulse\Facades\Pulse {}
class Livewire extends \Livewire\Livewire {}
class Health extends \Spatie\Health\Facades\Health {}
class Flare extends \Spatie\LaravelIgnition\Facades\Flare {}
}

Expand Down
43 changes: 43 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@

namespace App\Providers;

use App\Enums\Queue;
use App\Services\PostService;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider;
use Spatie\CpuLoadHealthCheck\CpuLoadCheck;
use Spatie\Health\Checks\Checks\CacheCheck;
use Spatie\Health\Checks\Checks\DatabaseCheck;
use Spatie\Health\Checks\Checks\DatabaseConnectionCountCheck;
use Spatie\Health\Checks\Checks\DebugModeCheck;
use Spatie\Health\Checks\Checks\EnvironmentCheck;
use Spatie\Health\Checks\Checks\HorizonCheck;
use Spatie\Health\Checks\Checks\OptimizedAppCheck;
use Spatie\Health\Checks\Checks\QueueCheck;
use Spatie\Health\Checks\Checks\RedisCheck;
use Spatie\Health\Checks\Checks\RedisMemoryUsageCheck;
use Spatie\Health\Checks\Checks\ScheduleCheck;
use Spatie\Health\Facades\Health;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -18,5 +32,34 @@ public function register(): void
public function boot(): void
{
Paginator::defaultView('components.pagination.default');

$checks = [
CacheCheck::new()->driver('redis'),
RedisCheck::new(),
QueueCheck::new()->onQueue(Queue::values()),
ScheduleCheck::new(),
HorizonCheck::new(),
DatabaseCheck::new(),
DatabaseConnectionCountCheck::new()
->warnWhenMoreConnectionsThan(70)
->failWhenMoreConnectionsThan(100),
RedisMemoryUsageCheck::new()->failWhenAboveMb(1000),
CpuLoadCheck::new()
->failWhenLoadIsHigherInTheLast5Minutes(2.0)
->failWhenLoadIsHigherInTheLast15Minutes(1.5),
];

if ($this->app->environment('production')) {
$checks = array_merge($checks, [
OptimizedAppCheck::new()
->checkConfig()
->checkRoutes()
->checkEvents(),
EnvironmentCheck::new(),
DebugModeCheck::new()->expectedToBe(false),
]);
}

Health::checks($checks);
}
}
22 changes: 13 additions & 9 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Jeffgreco13\FilamentBreezy\BreezyCore;
use Mvenghaus\FilamentScheduleMonitor\FilamentPlugin as ScheduleMonitorFilamentPlugin;
use ShuvroRoy\FilamentSpatieLaravelHealth\FilamentSpatieLaravelHealthPlugin;

class AdminPanelProvider extends PanelProvider
{
Expand All @@ -40,11 +41,11 @@ public function register(): void

FilamentView::registerRenderHook(
PanelsRenderHook::STYLES_BEFORE,
fn (): string => $this->app->make(BladeCompiler::class)->render('@livewireStyles'),
fn(): string => $this->app->make(BladeCompiler::class)->render('@livewireStyles'),
);
FilamentView::registerRenderHook(
PanelsRenderHook::STYLES_AFTER,
fn (): string => $this->app->make(BladeCompiler::class)->render('@livewireScripts'),
fn(): string => $this->app->make(BladeCompiler::class)->render('@livewireScripts'),
);
}

Expand All @@ -68,20 +69,20 @@ public function panel(Panel $panel): Panel
->login()
->navigationItems([
NavigationItem::make('Telescope')
->visible(fn () => $this->app->make(Guard::class)->user()?->can(Permissions::VIEW_TELESCOPE))
->visible(fn() => $this->app->make(Guard::class)->user()?->can(Permissions::VIEW_TELESCOPE))
->group('Monitoring')
->icon('heroicon-o-eye')
->url('/'.rtrim($configRepository->get('telescope.path'))),
->url('/' . rtrim($configRepository->get('telescope.path'))),
NavigationItem::make('Horizon')
->visible(fn () => $this->app->make(Guard::class)->user()?->can(Permissions::VIEW_HORIZON))
->visible(fn() => $this->app->make(Guard::class)->user()?->can(Permissions::VIEW_HORIZON))
->group('Monitoring')
->icon('heroicon-o-queue-list')
->url('/'.rtrim($configRepository->get('horizon.path'))),
->url('/' . rtrim($configRepository->get('horizon.path'))),
NavigationItem::make('Pulse')
->visible(fn () => $this->app->make(Guard::class)->user()?->can(Permissions::VIEW_PULSE))
->visible(fn() => $this->app->make(Guard::class)->user()?->can(Permissions::VIEW_PULSE))
->group('Monitoring')
->icon('heroicon-o-heart')
->url('/'.rtrim($configRepository->get('pulse.path'))),
->url('/' . rtrim($configRepository->get('pulse.path'))),
])
->colors([
'primary' => Color::Blue,
Expand Down Expand Up @@ -115,6 +116,9 @@ public function panel(Panel $panel): Panel
])
->plugins([
ScheduleMonitorFilamentPlugin::make(),
FilamentSpatieLaravelHealthPlugin::make()
->navigationLabel('Health')
->navigationGroup('Monitoring'),
FilamentSpatieRolesPermissionsPlugin::make(),
BreezyCore::make()
->myProfile(
Expand All @@ -126,7 +130,7 @@ public function panel(Panel $panel): Panel
force: app()->environment('production')
)
->enableSanctumTokens()
->avatarUploadComponent(fn (): FileUpload => FileUpload::make('avatar_url')->disk('profile-photos'))
->avatarUploadComponent(fn(): FileUpload => FileUpload::make('avatar_url')->disk('profile-photos'))
->passwordUpdateRules(
rules: [
Password::default()
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"aws/aws-sdk-php": "^3.336",
"codelieutenant/laravel-crypto": "^v1.0.0",
"codelieutenant/laravel-pgenum": "^1.0",
"doctrine/dbal": "^3.7",
"doctrine/dbal": "^3.9",
"filament/filament": "^3.2",
"guzzlehttp/guzzle": "^7.8",
"http-interop/http-factory-guzzle": "^1.2",
Expand All @@ -43,8 +43,11 @@
"livewire/livewire": "^v3.4",
"mvenghaus/filament-plugin-schedule-monitor": "^3.0",
"pusher/pusher-php-server": "^7.2",
"shuvroroy/filament-spatie-laravel-health": "^2.3",
"spatie/cpu-load-health-check": "^1.0",
"spatie/fork": "^1.2",
"spatie/laravel-permission": "^6.10.1",
"spatie/laravel-schedule-monitor": "^3.9",
"spatie/laravel-sitemap": "^7.0",
"symfony/cache": "^v7.0",
"tpetry/laravel-postgresql-enhanced": "^2.0",
Expand Down
Loading

0 comments on commit f973441

Please sign in to comment.