A package providing configurable interface to export Prometheus metrics in Laravel
aduzenko/laravel-configurable-prometheus is a Laravel package for a package providing configurable interface to export prometheus metrics in laravel.
It currently has 1 GitHub stars and 37 downloads on Packagist (latest version v1.0.1).
Install it with composer require aduzenko/laravel-configurable-prometheus.
Discover more Laravel packages by aduzenko
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package for defining, managing, and exporting Prometheus metrics in a flexible, extensible way.
composer require aduzenko/laravel-configurable-prometheus
php artisan vendor:publish --tag=prometheus-config
This will publish:
config/prometheus.phpThe Prometheus endpoint is protected from unauthorized access by basic HTTP authentication.
.env filePROMETHEUS_USER=prom
PROMETHEUS_PASSWORD=secret
The Prometheus endpoint is configurable.
config/prometheus.php file'endpoint' => 'prometheus',
Define a class implementing MetricGroup:
namespace App\Metrics;
use AnatolyDuzenko\ConfigurablePrometheus\DTO\MetricDefinition;
use AnatolyDuzenko\ConfigurablePrometheus\Enums\MetricType;
use AnatolyDuzenko\ConfigurablePrometheus\Contracts\MetricGroup;
class ApiMetrics implements MetricGroup
{
public function definitions(): array
{
return [
new MetricDefinition(
namespace: 'api',
name: 'response_time_seconds',
helpText: 'API response time',
type: MetricType::Histogram,
labelNames: ['route'],
buckets: [0.1, 0.3, 0.5, 1, 2, 5]
)
];
}
}
Then reference your group in config/prometheus.php:
'groups' => [
\App\Metrics\ApiMetrics::class,
],
// In your class constructor, use
public function __construct(protected MetricManager $metrics)
{}
// then
$this->metrics->inc('users', 'user_logins_total', ['web']);
$this->metrics->set('users', 'active_users', 42, ['web']);
$this->metrics->observe('api', 'response_time_seconds', 0.32, ['/api/v1']);
// In your method
public function index(Request $request, MetricManager $metrics)
{
// ....
$metrics->inc('users', 'user_logins_total', ['web']);
$metrics->set('users', 'active_users', 42, ['web']);
$metrics->observe('api', 'response_time_seconds', 0.32, ['/api/v1']);
}
vendor/bin/phpunit
MIT ยฉ Anatoly Duzenko