Skip to content

Commit e46585e

Browse files
authored
Merge pull request #54 from dsbilling/add-health-checks
2 parents a1b070e + fb26cce commit e46585e

File tree

11 files changed

+778
-2
lines changed

11 files changed

+778
-2
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ BLOG_USES_SLUG=null
5454

5555
SENTRY_LARAVEL_DSN=null
5656
SENTRY_TRACES_SAMPLE_RATE=0
57+
58+
OH_DEAR_API_TOKEN=
59+
OH_DEAR_SITE_ID=
60+
OH_DEAR_HEALTH_CHECK_SECRET=

app/Console/Commands/Update.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function handle()
2929
{
3030
$this->info('Migrating...');
3131
$this->call('migrate --force');
32+
$this->info('Sync schedule monitor...');
33+
$this->call('schedule-monitor:sync');
3234
return Command::SUCCESS;
3335
}
3436
}

app/Console/Kernel.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Console\Scheduling\Schedule;
66
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
use Spatie\Health\Commands\RunHealthChecksCommand;
8+
use Spatie\Health\Commands\ScheduleCheckHeartbeatCommand;
9+
use Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem;
710

811
class Kernel extends ConsoleKernel
912
{
@@ -15,7 +18,11 @@ class Kernel extends ConsoleKernel
1518
*/
1619
protected function schedule(Schedule $schedule)
1720
{
18-
// $schedule->command('inspire')->hourly();
21+
// Often commands
22+
$schedule->command(RunHealthChecksCommand::class)->everyMinute();
23+
$schedule->command(ScheduleCheckHeartbeatCommand::class)->everyMinute();
24+
// Daily commands
25+
$schedule->command('model:prune', ['--model' => MonitoredScheduledTaskLogItem::class])->daily();
1926
}
2027

2128
/**
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use Spatie\CpuLoadHealthCheck\CpuLoadCheck;
7+
use Spatie\Health\Checks\Checks\DatabaseCheck;
8+
use Spatie\Health\Checks\Checks\DebugModeCheck;
9+
use Spatie\Health\Checks\Checks\EnvironmentCheck;
10+
use Spatie\Health\Checks\Checks\ScheduleCheck;
11+
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
12+
use Spatie\Health\Facades\Health;
13+
14+
class HealthCheckServiceProvider extends ServiceProvider
15+
{
16+
/**
17+
* Register services.
18+
*
19+
* @return void
20+
*/
21+
public function register()
22+
{
23+
//
24+
}
25+
26+
/**
27+
* Bootstrap services.
28+
*
29+
* @return void
30+
*/
31+
public function boot()
32+
{
33+
// If staging is in app url and in env set expect env to staging
34+
$env = 'production';
35+
if (config('app.env') == 'staging' and str_contains(config('app.url'), 'staging')) {
36+
$env = 'staging';
37+
}
38+
Health::checks([
39+
UsedDiskSpaceCheck::new(),
40+
DatabaseCheck::new(),
41+
CpuLoadCheck::new()
42+
->failWhenLoadIsHigherInTheLast5Minutes(2.0)
43+
->failWhenLoadIsHigherInTheLast15Minutes(1.5),
44+
DebugModeCheck::new(),
45+
EnvironmentCheck::new()->expectEnvironment($env),
46+
ScheduleCheck::new(),
47+
]);
48+
}
49+
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
"mtownsend/read-time": "^2.0",
2323
"romanzipp/laravel-seo": "^2.4",
2424
"sentry/sentry-laravel": "^3.1",
25+
"spatie/cpu-load-health-check": "^1.0",
26+
"spatie/laravel-health": "^1.22",
2527
"spatie/laravel-honeypot": "^4.1",
2628
"spatie/laravel-markdown": "^2.2",
2729
"spatie/laravel-permission": "^5.5",
30+
"spatie/laravel-schedule-monitor": "^3.2",
2831
"spatie/laravel-tags": "^4.3"
2932
},
3033
"require-dev": {

0 commit comments

Comments
 (0)