Skip to content

Commit e26a1a0

Browse files
committed
Merge branch 'release/1.2.0'
2 parents cb4df55 + eecef1a commit e26a1a0

File tree

3 files changed

+80
-12
lines changed

3 files changed

+80
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Oh Dear Application Health checker for Craft CMS.
44

5+
## 1.2.0 – 2025-09-17
6+
### Added
7+
- Add disk usage check and config options
8+
59
## 1.1.3 – 2025-07-15
610
### Changed
711
- Update default warning for oldest update to 40 days

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
<h1 align="center">Oh Dear Application Health checker for Craft CMS</h1>
44

5-
This plugin provides a [Oh Dear](https://ohdear.app) Application Health checker [Craft CMS](https://craftcms.com/).
5+
This plugin provides an [Oh Dear](https://ohdear.app) Application Health checker for [Craft CMS](https://craftcms.com/).
66

77
## 🚦 Health Checks Overview
88

9-
This plugin performs the following health checks and provides a JSON feed on yourwebsite.com/application-health.json for Oh Dear.
9+
This plugin performs the following health checks and provides a JSON feed at `/application-health.json` for Oh Dear.
1010

11-
The response is cached for 5 minutes.
11+
The response is cached for 5 minutes.
1212

1313
### ✅ Updates
14-
Checks if updates are available for Craft CMS and installed plugins.
14+
Checks if updates are available for Craft CMS and installed plugins, including critical ones.
1515

1616
### ✅ Queue Status
17-
Monitors the number of jobs in the queue and detects any failed jobs.
17+
Monitors the number of jobs in the queue and detects failed, reserved, or delayed jobs using configurable thresholds.
1818

1919
### ✅ Pending Migrations
2020
Verifies if there are any unapplied database migrations.
@@ -32,11 +32,15 @@ Fetches site headers and verifies the presence of key security headers (e.g., CS
3232
Confirms if the project configuration is fully synchronized.
3333

3434
### ✅ PHP Version
35-
Reports the active PHP version running on the server and verifies against a minimum required version.
35+
Reports the active PHP version running on the server and verifies it against a minimum required version.
3636

3737
### ✅ Admin Users
3838
Lists all admin users and flags users who haven’t logged in for a configurable period.
3939

40+
### ✅ Disk Usage
41+
Monitors disk space usage and flags if usage exceeds a configurable threshold.
42+
*(Disabled by default to avoid noise on shared servers.)*
43+
4044
## Requirements
4145

4246
This plugin requires Craft CMS 4.0.0+ or 5.0.0+.
@@ -54,13 +58,13 @@ Go to the Plugin Store in your project’s Control Panel and search for “Oh De
5458
Open your terminal and run the following commands:
5559

5660
```bash
57-
# go to the project directory
61+
# Go to the project directory
5862
cd /path/to/my-project.test
5963

60-
# tell Composer to load the plugin
64+
# Tell Composer to load the plugin
6165
composer require perfectwebteam/craft-ohdear-application-health
6266

63-
# tell Craft to install the plugin
67+
# Tell Craft to install the plugin
6468
./craft plugin/install ohdear-application-health
6569
```
6670

@@ -89,6 +93,7 @@ return [
8993
'addSecurityHeadersCheck' => true,
9094
'addPhpVersionCheck' => true,
9195
'addAdminUsersCheck' => true,
96+
'addDiskUsageCheck' => false,
9297
],
9398
'oldestUpdateWarningDays' => 30,
9499
'minimumPhpVersion' => '8.1.0',
@@ -103,7 +108,9 @@ return [
103108
'inactiveAdminThreshold' => '-1 year',
104109
'gitRepoPath' => '@root',
105110
'queueTotalThreshold' => 10,
106-
'queueFailedThreshold' => 2
111+
'queueFailedThreshold' => 2,
112+
'diskUsagePath' => '/',
113+
'diskUsageThreshold' => 90,
107114
];
108115
```
109116

src/services/HealthCheckService.php

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ public function runChecks(): CheckResults
3636
'addGitChangesCheck',
3737
'addSecurityHeadersCheck',
3838
'addPhpVersionCheck',
39-
'addAdminUsersCheck'
39+
'addAdminUsersCheck',
40+
'addDiskUsageCheck'
4041
] as $check) {
41-
if (($enabledChecks[$check] ?? true) === true) {
42+
$defaultEnabled = ($check === 'addDiskUsageCheck') ? false : true;
43+
44+
if (($enabledChecks[$check] ?? $defaultEnabled) === true) {
4245
$this->$check($results);
4346
}
4447
}
@@ -447,4 +450,58 @@ private function addAdminUsersCheck(CheckResults $checkResults): void
447450
meta: $adminMeta
448451
));
449452
}
453+
454+
private function addDiskUsageCheck(CheckResults $checkResults): void
455+
{
456+
$path = $this->config['diskUsagePath'] ?? '/';
457+
$threshold = $this->config['diskUsageThreshold'] ?? 90;
458+
459+
$meta = [];
460+
$status = CheckResult::STATUS_OK;
461+
462+
try {
463+
$totalSpace = disk_total_space($path);
464+
$freeSpace = disk_free_space($path);
465+
466+
if ($totalSpace === false || $freeSpace === false || $totalSpace === 0) {
467+
throw new \Exception("Unable to retrieve disk space for path: {$path}");
468+
}
469+
470+
$usedSpace = $totalSpace - $freeSpace;
471+
$usedPercentage = round(($usedSpace / $totalSpace) * 100, 2);
472+
473+
$meta = [
474+
'Path' => $path,
475+
'Total space (GB)' => round($totalSpace / (1024 ** 3), 2),
476+
'Used space (GB)' => round($usedSpace / (1024 ** 3), 2),
477+
'Free space (GB)' => round($freeSpace / (1024 ** 3), 2),
478+
'Used (%)' => "{$usedPercentage}%",
479+
];
480+
481+
if ($usedPercentage >= $threshold) {
482+
$status = CheckResult::STATUS_FAILED;
483+
$message = "Disk usage at {$usedPercentage}% exceeds threshold ({$threshold}%)";
484+
} else {
485+
$message = "Disk usage is at {$usedPercentage}%";
486+
}
487+
488+
$checkResults->addCheckResult(new CheckResult(
489+
name: 'DiskUsage',
490+
label: 'Disk Usage Check',
491+
notificationMessage: $message,
492+
shortSummary: "{$usedPercentage}%",
493+
status: $status,
494+
meta: $meta
495+
));
496+
} catch (\Exception $e) {
497+
$checkResults->addCheckResult(new CheckResult(
498+
name: 'DiskUsage',
499+
label: 'Disk Usage Check',
500+
notificationMessage: 'Error checking disk usage.',
501+
shortSummary: 'Disk usage check failed',
502+
status: CheckResult::STATUS_FAILED,
503+
meta: ['Error' => $e->getMessage()]
504+
));
505+
}
506+
}
450507
}

0 commit comments

Comments
 (0)