PHP code example of yidas / mtr-database

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

    

yidas / mtr-database example snippets


...
    'database' => [
        'host' => '',
        'driver'    => 'mysql',
        'database'  => 'mtr_database',
        'username'  => '',
        'password'  => '',
        'table' => 'records',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
    ],
...

...
    'general' => [
        'mtrCmd' => 'mtr',
        'timezone' => 'Asia/Taipei',
        'category' => 'agent-01',   // Category mark for distinguishing
    ],
    'mtr' => [
        'host' => 'your.host',
        'period' => 10,     // Minute
        'count' => 60,      // Report-cycles
        'tcp' => false,     // TCP mode
        'port' => 443,      // Port number for TCP mode
    ],
    'api' => [
        'key' => '',            // API key must be the same bewteen agent and collector
        'agent' => [
            'enabled' => false, // To send MTR data to collector via API Agent (deafult is database)
            'reportUrl' => '',  // Collector's API URL
        ],
        'collector' => [
            'enabled' => false, // To receive MTR data from agent via API
        ],
    ],
...

    'api' => [
        'key' => 'your-own-api-key',            // API key must be the same bewteen agent and collector
        'agent' => [
            'enabled' => false, // To send MTR data to collector via API Agent (deafult is database)
            'reportUrl' => '',  // Collector's API URL
        ],
        'collector' => [
            'enabled' => true,  // To receive MTR data from agent via API
        ],
    ],
    'database' => [

    'api' => [
        'key' => 'your-own-api-key',            // API key must be the same bewteen agent and collector
        'agent' => [
            'enabled' => true, // To send MTR data to collector via API Agent (deafult is database)
            'reportUrl' => 'https://your.host/mtr-database/collect.php',  // Collector's API URL
        ],
        'collector' => [
            'enabled' => false, // To receive MTR data from agent via API
        ],
    ],

...
    'dashboard' => [
        'enabled' => true,
        'username' => '',
        'password' => '',
        'categories' => [''],   // Category list for selection
    ],
    'database' => [
...
shell
$ wget https://github.com/yidas/mtr-database-php/archive/master.tar.gz -O mtr-database-phpi.tar.gz
shell
$ tar -zxvf mtr-database-php.tar.gz
shell
$ php install.php
Installation completed
shell
$php launch.php
Process success
shell
# Launch and record MTR every 10 miniutes by default ('period' => 10)
*/10 * * * * root php /var/www/html/mtr-database/launch.php >/dev/null 2>&1

# Purge data before 90 days by default (Optional)
00 00 * * * root php /var/www/html/mtr-database/purge.php >/dev/null 2>&1
shell
php launch.php --host="yourhost.local"
shell
# Launch and record MTR every 5 miniutes
*/5 * * * * root php /var/www/html/mtr-database/launch.php --period=5 >/dev/null 2>&1
shell
php launch.php --tcp -port=443
shell
php launch.php --category="Monitor-A1"
shell
00 00 * * * root php /var/www/html/mtr-database/purge.php --days=30 >/dev/null 2>&1