PHP code example of staabm / sysmonitor

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

    

staabm / sysmonitor example snippets


// sends notificaitons on urgent events
$notifier = new SeverityNotifier(new MyCustomNotifier(), SystemEvent::SEVERITY_URGENT);
// main class which collects all the data
$monitor = new SystemMonitor(new SystemEventStorage(), new MyRequestEnvImpl(), $notifier);

register_shutdown_function(function() {
    $requestStats = new RequestStatsEvent();
    // data from your db class
    $requestStats->usedQueries = DB::$num_of_queries;
    $requestStats->usedConnections = DB::$num_of_connections;
    // data from your runtime
    $requestStats->peakMemory = number_format(memory_get_peak_usage(true) / 1024 / 1024);
    
    // retrieve the monitor instance, e.g. via a DIC/a registry/singleton/whatever
    // $monitor = .. 
    $monitor->collectStats($requestStats);
});

set_exception_handler(function() {
    $event = new RequestExceptionEvent();
    $event->exception = $exception;
    
    // retrieve the monitor instance, e.g. via a DIC/a registry/singleton/whatever
    // $monitor = .. 
    $monitor->collectException($event);
});