PHP code example of mindtwo / base-monitoring

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


use Mindtwo\Monitoring\Monitor;

// A monitor with the full default collector catalog:
$monitor = Monitor::make(projectRoot: '/var/www/my-project');

$snapshot = $monitor->snapshot();

$snapshot->toArray(); // structured payload
$snapshot->toJson();  // wire format

use Mindtwo\Monitoring\Data\Credentials;
use Mindtwo\Monitoring\Monitor;
use Mindtwo\Monitoring\Transport\HttpTransport;

$transport = new HttpTransport(
    endpoint: 'https://monitoring.mindtwo.com/api/monitoring',
    credentials: new Credentials('prj_live_8f3a…', $secret),
);

$result = Monitor::make()->push($transport);

$result->success;    // bool — transports never throw
$result->statusCode; // ?int
$result->error;      // ?string

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

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

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

$monitor->register(new DockerCollector());          // throws on duplicate keys
$monitor->replace(new MyBetterDatabaseCollector()); // intentional override
$monitor->addCustomData('deployment', fn () => ['region' => 'eu-central-1']);

use Mindtwo\Monitoring\Transport\HmacRequestSigner;
use Mindtwo\Monitoring\Transport\HmacSignatureVerifier;

$headers = (new HmacRequestSigner)->headers($payload, $credentials);   // outbound
$valid = (new HmacSignatureVerifier)->verify($payload, $headers, $credentials); // inbound
text
signature = hex( hmac_sha256( "{timestamp}.{payload}", secret ) )