triadev / laravel-prometheus-exporter
A laravel and lumen service provider to export metrics for prometheus.
Installs: 25 690
Dependents: 1
Suggesters: 0
Security: 0
Stars: 28
Watchers: 1
Forks: 19
Open Issues: 4
Requires
- php: >=7.2
- endclothing/prometheus_client_php: ^1.0
- illuminate/support: ^5.6|^6.0
Requires (Dev)
- fzaninotto/faker: ~1.4
- laravel/framework: ^5.6|^6.0
- laravel/lumen-framework: ^5.6|^6.0
- mockery/mockery: ~1.0
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~7.0
- squizlabs/php_codesniffer: ^3.0
Suggests
- ext-apc: Required if using APCu.
- ext-redis: Required if using Redis.
README
A laravel and lumen service provider to export metrics for prometheus.
Supported laravel versions
Supported lumen versions
Main features
- Metrics with APC
- Metrics with Redis
- Metrics with InMemory
- Metrics with the push gateway
- Request per route middleware (total and duration metrics)
Installation
Composer
composer require triadev/laravel-prometheus-exporter
Application
The package is registered through the package discovery of laravel and Composer.
Once installed you can now publish your config file and set your correct configuration for using the package.
php artisan vendor:publish --provider="Triadev\PrometheusExporter\Provider\PrometheusExporterServiceProvider" --tag="config"
This will create a file config/prometheus-exporter.php
.
Configuration
buckets_per_route
'buckets_per_route' => [
ROUTE-NAME => [10,20,50,100,200],
...
]
Usage
Get metrics
Laravel
When you are using laravel you can use the default http endpoint:
triadev/pe/metrics
Of course you can also register your own route. Here is an example:
Route::get(
ROUTE,
\Triadev\PrometheusExporter\Controller\LaravelController::class . '@metrics'
);
Lumen
When you are using lumen you must register the route on your own. Here is an example:
Route::get(
ROUTE,
\Triadev\PrometheusExporter\Controller\LumenController::class . '@metrics'
);
Middleware
RequestPerRoute
A middleware to build metrics for "request_total" and "requests_latency_milliseconds" per route.
Alias
lpe.requestPerRoute
Metrics
- requests_total (inc)
- requests_latency_milliseconds (histogram)
Example
$router->get('/test/route', function () { return 'valid'; })->middleware('lpe.requestPerRoute');
app_requests_latency_milliseconds_bucket{route="/test/route",method="GET",status_code="200",le="0.005"} 0 ... app_requests_latency_milliseconds_count{route="/test/route",method="GET",status_code="200"} 1 app_requests_latency_milliseconds_sum{route="/test/route",method="GET",status_code="200"} 6 app_requests_total{route="/test/route",method="GET",status_code="200"} 1
Roadmap
- histogram buckets per route (RequestPerRoute)
Reporting Issues
If you do find an issue, please feel free to report it with GitHub's bug tracker for this project.
Alternatively, fork the project and make a pull request. :)
Testing
- docker-compose up
- docker exec fpm ./vendor/phpunit/phpunit/phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
Other
Project related links
Author
License
The code for LaravelPrometheusExporter is distributed under the terms of the MIT license (see LICENSE).