PHP code example of ericmakesstuff / laravel-server-monitor

1. Go to this page and download the library: Download ericmakesstuff/laravel-server-monitor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ericmakesstuff / laravel-server-monitor example snippets


// config/app.php

'providers' => [
    // ...
    EricMakesStuff\ServerMonitor\ServerMonitorServiceProvider::class,
];

'monitors' => [
    /*
     * DiskUsage will alert when the free space on the device exceeds the alarmPercentage.
     * path is any valid file path, and the monitor will look at the usage of that disk partition.
     *
     * You may add as many DiskUsage monitors as you checkPhrase is not found in the response.
     */
    'HttpPing' => [
        [
            'url' => 'http://www.example.com/',
        ],
        [
            'url' => 'http://www.example.com/',
            'checkPhrase' => 'Example Domain',
            'timeout' => 10,
            'allowRedirects' => false,
        ],
    ],
    /*
     * SSLCertificate will download the SSL Certificate for the URL and validate that the domain
     * is covered and that it is not expired. Additionally, it can warn when the certificate is
     * approaching expiration.
     */
    'SSLCertificate' => [
        [
            'url' => 'https://www.example.com/',
        ],
        [
            'url' => 'https://www.example.com/',
            'alarmDaysBeforeExpiration' => [14, 7],
        ],
    ],

'events' => [
    'whenDiskUsageHealthy'       => ['log'],
    'whenDiskUsageAlarm'         => ['log', 'mail'],
    'whenHttpPingUp'             => ['log'],
    'whenHttpPingDown'           => ['log', 'mail'],
    'whenSSLCertificateValid'    => ['log'],
    'whenSSLCertificateInvalid'  => ['log', 'mail'],
    'whenSSLCertificateExpiring' => ['log', 'mail'],
],

// app/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
   $schedule->command('monitor:run')->daily()->at('10:00');
   $schedule->command('monitor:run HttpPing')->hourly();
}
 bash
php artisan monitor:run
 bash
php artisan monitor:run HttpPing
php artisan monitor:run SSLCertificate,DiskUsage