PHP code example of mindtwo / laravel-monitoring

1. Go to this page and download the library: Download mindtwo/laravel-monitoring 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/ */

    

mindtwo / laravel-monitoring example snippets


// config/monitoring.php
'collectors' => [
    // ...defaults...
    \App\Monitoring\HorizonCollector::class,
],

namespace App\Monitoring;

use Mindtwo\Monitoring\Collectors\AbstractCollector;
use Mindtwo\Monitoring\Data\CollectionResult;

final class HorizonCollector extends AbstractCollector
{
    public function key(): string
    {
        return 'horizon';
    }

    public function collect(): CollectionResult
    {
        return CollectionResult::ok($this->key(), [
            'status' => 'running',
        ]);
    }
}

use Mindtwo\Monitoring\Laravel\Facades\Monitoring;

Monitoring::addCustomData('deployment', fn () => [
    'region' => config('app.region'),
    'release' => exec_free_release_id(),
]);

$this->app->singleton(\Mindtwo\Monitoring\Contracts\Transport::class, MyTransport::class);

use Illuminate\Support\Facades\Http;

Http::fake(['monitoring.mindtwo.com/*' => Http::response('', 200)]);

$this->artisan('monitoring:push')->assertExitCode(0);

Http::assertSent(fn ($request) => $request->hasHeader('X-Monitoring-Signature'));
bash
php artisan vendor:publish --tag=monitoring-config
text
+---------------------+--------+----------------------------+
| Metric              | Status | Details                    |
+---------------------+--------+----------------------------+
| os                  | ok     | macos 14.4.1               |
| php                 | ok     | php 8.3.2                  |
| database            | ok     | mysql 8.0.36               |
| laravel             | ok     | laravel 11.9.0             |
| composer_packages   | ok     | 73 packages                |
| composer_audit      | ok     |                            |
| nginx               | unsup… |                            |
+---------------------+--------+----------------------------+