click/laravel-prometheus-metrics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

click/laravel-prometheus-metrics

最新稳定版本:1.0.1

Composer 安装命令:

composer require click/laravel-prometheus-metrics

包简介

Framework-agnostic Laravel middleware for Prometheus metrics collection

README 文档

README

A simple and extensible Laravel package for collecting and exposing metrics in the Prometheus format. Ideal as a starting point for building custom monitoring solutions.

🚀 Features

  • Ready-to-use /metrics endpoint for Prometheus scraping
  • Flexible and centralized configuration
  • Extensible architecture with support for custom collectors
  • Histogram buckets for operation duration tracking
  • Cache support to reduce overhead

📦 Installation

composer require click/laravel-prometheus-metrics

⚙️ Publishing Configuration

Publish the configuration file using Artisan:

php artisan vendor:publish --tag=prometheus-config
Option Description Default
route_path The path to expose metrics /metrics
cache_ttl Cache duration in seconds (uses Laravel Cache) 3600 (1 hour)
prefix Metric name prefix (can be set via PREFIX_PROMETHEUS_METRICS env var) ''
buckets Histogram buckets for measuring durations [0.01, 0.05, 0.1, 0.3, 0.5, 1]

🌐 Routes

After installation, the following route becomes available automatically:

GET /metrics

This route exposes metrics in Prometheus text exposition format.

🧩 Middleware Integration

You can attach Prometheus metric collection to specific routes via middleware.

Option 1: Using an alias

Register the alias in your config/app.php:

'aliases' => [
    'prometheus' => \YourVendor\Prometheus\Middleware\PrometheusMiddleware::class,
    // ...
],

Then apply the middleware by alias:

use Illuminate\Support\Facades\Route;

Route::get('/health', fn() => ['ok' => true])
    ->middleware('prometheus');

Option 2: Using the class directly

use YourVendor\Prometheus\Middleware\PrometheusMiddleware;

Route::get('/health', fn() => ['ok' => true])
->middleware([PrometheusMiddleware::class]);

统计信息

  • 总下载量: 294
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-05-07