PHP application health monitoring

Oh Dear can monitor the health of any PHP, no matter which framework it uses or language is written in.

We will not run any health check from our end. Your application or infrastructure should run any desired checks. The results of the checks should be made available at an HTTP endpoint.

Every couple of minutes Oh Dear will visit that endpoint to get the check results. The endpoint URL can be configured at the application health settings screen.

screenshot

The request that Oh Dear sends to your app will contain a secret value in the oh-dear-health-check-secret header. To make sure that a request really comes from Oh Dear, you should verify if the secret value is correct.

Building the health checks results JSON in PHP

That endpoint must return the health check results as JSON in a specific format. That format is described on this page.

To help you construct the required JSON, you can use the ohdearapp/health-check-results package.

Here's an example that shows how you can create the JSON that Oh Dear expects.

$checkResults = new CheckResults(DateTime::createFromFormat('Y-m-d H:i:s', '2021-01-01 00:00:00'));

$checkResult = new CheckResult(
    name: 'UsedDiskSpace',
    label: 'Used disk space',
    notificationMessage: 'Your disk is almost full (91%)',
    shortSummary: '91%',
    status: CheckResult::STATUS_FAILED,
    meta: ['used_disk_space_percentage' => 91]
);

$checkResults->addCheckResult($checkResult);

echo $checkResults->toJson();

This will output this JSON:

{
    "finishedAt": 1609459200,
    "checkResults": [
        {
            "name": "UsedDiskSpace",
            "label": "Used disk space",
            "notificationMessage": "Your disk is almost full (91%)",
            "shortSummary": "91%",
            "status": "failed",
            "meta": {
                "used_disk_space_percentage": 91
            }
        }
    ]
}

Was this page helpful to you? Feel free to reach out via support@ohdear.app or on Twitter via @OhDearApp if you have any other questions. We'd love to help!