tech-djoin/laravel-prometheus

0.2.8 2023-11-03 03:21 UTC

This package is auto-updated.

Last update: 2024-11-03 08:26:20 UTC


README

Latest Version on Packagist Total Downloads License: MIT

Laravel Prometheus is a package that allows you to integrate Prometheus, a popular open-source monitoring and alerting toolkit, into your Laravel applications. Prometheus is widely used for monitoring various aspects of software systems, including metrics, time series data, and alerting.

This package uses Redis to do the client side aggregation and also need installed phpredis extension for communication with the Redis key-value store. To install the phpredis extension you can follow link below:

https://github.com/phpredis/phpredis/blob/develop/INSTALL.md

Installation

You can install the package via composer:

composer require tech-djoin/laravel-prometheus

You can publish the config file with:

php artisan vendor:publish --provider="TechDjoin\LaravelPrometheus\PrometheusServiceProvider" --tag="config" 

Usage

This packages provides a middleware which can be added as a global middleware or as a single route.

// in `app/Http/Kernel.php`

protected $middleware = [
    // ...
    
    \TechDjoin\LaravelPrometheus\Middleware\MetricCollector::class
];
// in a routes file

Route::post('/dashboard', function () {
    //
})->middleware(\TechDjoin\LaravelPrometheus\Middleware\MetricCollector::class);

Exporting Metrics

This package adds a /metrics end-point, enabled by default, which exposes all metrics gathered by collectors.

If you would like to protect this end-point, you can add secret value on LARAVEL_PROMETHEUS_SECRET in your .env files, and you can only access the end-point using /metrics/{secret}

Testing

composer test

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Contributors