ALTELMA / laravel-prometheus-exporter by ALTELMA

A Prometheus exporter for Laravel and Lumen
6,078
1
1
Package Data
Maintainer Username: ALTELMA
Maintainer Contact: nrohtgnohp@gmail.com (ALTELMA)
Package Create Date: 2022-12-29
Package Last Update: 2023-01-11
Language: PHP
License: MIT
Last Refreshed: 2024-12-17 03:09:19
Package Statistics
Total Downloads: 6,078
Monthly Downloads: 440
Daily Downloads: 17
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Laravel Prometheus Exporter

Software License Latest Version on Packagist Total Downloads

A prometheus exporter package for Laravel and Lumen.

This package is a wrapper bridging promphp/prometheus_client_php into Laravel and Lumen.

However, This package get inspire from another package below

Feel free to use above package instead, because this package just try to cover compatibility for previous version of Laravel and Lumen such as 6.x to 8.x, etc.

Installation

Install the package via composer

composer require altelma/laravel-prometheus-exporter

If you are using Lumen need to register the service provider in bootstrap/app.php

$app->register(Altelma\LaravelPrometheusExporter\PrometheusServiceProvider::class);

Configuration

The package has a default configuration which uses the following environment variables.

PROMETHEUS_NAMESPACE=app

PROMETHEUS_METRICS_ROUTE_ENABLED=true
PROMETHEUS_METRICS_ROUTE_PATH=metrics
PROMETHEUS_METRICS_ROUTE_MIDDLEWARE=null
PROMETHEUS_COLLECT_FULL_SQL_QUERY=true
PROMETHEUS_STORAGE_ADAPTER=memory

PROMETHEUS_REDIS_HOST=localhost
PROMETHEUS_REDIS_PORT=6379
PROMETHEUS_REDIS_TIMEOUT=0.1
PROMETHEUS_REDIS_READ_TIMEOUT=10
PROMETHEUS_REDIS_PERSISTENT_CONNECTIONS=0
PROMETHEUS_REDIS_PREFIX=PROMETHEUS_

Metrics

The package allows you to observe metrics on the application routes. Metrics on request method, request path and status code.

Laravel

In order to observe metrics in Laravel application routes (the time between a request and response), you should register the following middleware in your application's app/Http/Kernel.php:

protected $middleware = [
    \Altelma\LaravelPrometheusExporter\Middleware\PrometheusLaravelMiddleware::class,
];

Lumen 9.x

In order to observe metrics in Lumen application routes (the time between a request and response), you should register the following middleware in your application's bootstrap/app.php:

$app->middleware([
    \Altelma\LaravelPrometheusExporter\Middleware\PrometheusLumenMiddleware::class,
]);

Lumen 8.x and Lower

In Lumen 8.x and lower, cannot get route in global middleware just need to do in route middleware instead

$app->routeMiddleware([
    'http.prometheus' => \Altelma\LaravelPrometheusExporter\Middleware\PrometheusLumenRouteMiddleware::class,
]);

สนับสนุนผมได้นะ ☕

สวัสดีเพื่อนๆ ทุกคนนะครับ หากมีข้อเสนอแนะอะไร แนะนำมาได้นะครับ นอกจากนี้ เพื่อนๆ สามารถแวะไปอ่านบทความของผมเพิ่มเติมได้ ที่นี่ ครับ

Bug Report

This package is not perfect right, but can be improve together. If you found bug or have any suggestion. Send that to me or new issue. Thank you to use it.