PHP code example of zlodes / prometheus-client-laravel
1. Go to this page and download the library: Download zlodes/prometheus-client-laravel 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/ */
zlodes / prometheus-client-laravel example snippets
use Illuminate\Support\Facades\Route;
use Zlodes\PrometheusClient\Laravel\Http\MetricsExporterController;
Route::get('/metrics', MetricsExporterController::class);
use Zlodes\PrometheusClient\Laravel\Storage\StorageConfigurator;
use Zlodes\PrometheusClient\Storage\Contracts\CounterStorage;
use Zlodes\PrometheusClient\Storage\Contracts\GaugeStorage;
use Zlodes\PrometheusClient\Storage\Contracts\HistogramStorage;
use Zlodes\PrometheusClient\Storage\Contracts\SummaryStorage;
// your ServiceProvider::register()
$this->callAfterResolving(
StorageConfigurator::class,
static function (StorageConfigurator $configurator): void {
$configurator->extend('my_driver', [
CounterStorage::class => MyCounterStorage::class,
GaugeStorage::class => MyGaugeStorage::class,
HistogramStorage::class => MyHistogramStorage::class,
SummaryStorage::class => MySummaryStorage::class,
]);
}
);
$this->callAfterResolving(Registry::class, static function (Registry $registry): void {
$registry
->registerMetric(
new Counter('dummy_controller_hits', 'Dummy controller hits count')
)
->registerMetric(
new Gauge('laravel_queue_size', 'Laravel queue length by Queue')
);
});
use Zlodes\PrometheusClient\Collector\CollectorFactory;
class DummyController
{
public function __invoke(CollectorFactory $collector)
{
$collector->counter('dummy_controller_hits')->increment();
}
}