PHP code example of cloudisle / laravel-prometheus

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

    

cloudisle / laravel-prometheus example snippets


return [
    'namespace' => 'myapp',
    'labels' => [
        'app' => 'myapp',
        'env' => env('APP_ENV'),
    ],
    'counters' => [
        [
            'name' => 'requests_total',
            'help' => 'Total HTTP requests',
            'labels' => ['route'], // array of label names
        ],
    ],
    // ...
];

use Metrics;

// Increment a counter (label values: [default labels..., route])
Metrics::increment('requests_total', ['path' => '/', 'route' => 'home']);

// Set a gauge
Metrics::record('memory_usage', 123.45, ['proc' => 'worker-1']);

// Observe a histogram
Metrics::observe('response_time', 0.234, ['resource' => 'api']);

// Summarize a value
Metrics::summarize('payload_size', 512, ['action' => 'upload']);

use Prometheus;

// Get a counter instance
$counter = Prometheus::counter('my_ns', 'my_counter', 'Help text', ['foo', 'bar']);
$counter->incBy(1, ['val1', 'val2']);
bash
   php artisan vendor:publish --provider="CloudIsle\Prometheus\PrometheusServiceProvider" --tag=config