Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Prometheus Client Php

Prometheus Client Php Laravel Package

promphp/prometheus_client_php

PHP Prometheus client library that uses Redis, Predis, APCu, or in-memory adapters for client-side aggregation. Register counters, gauges, histograms, and summaries, then expose metrics in Prometheus text format.

View on GitHub
Deep Wiki
Context7

A PHP Prometheus client library for instrumenting applications with counters, gauges, histograms, and summaries. It performs client-side metric aggregation using Redis, Predis, APC, APCng, or an in-memory adapter, making it suited to PHP worker processes that do not share state.

  • Multiple storage adapters: Redis, Predis, APC, APCng, and in-memory.
  • Collector registry: register and retrieve metrics via getOrRegister... helpers.
  • Core metric types: counters, gauges, histograms, and summaries.
  • Prometheus exposition: render metrics with RenderTextFormat.
  • Simple Composer installation and lightweight API for quick instrumentation.
Frequently asked questions about Prometheus Client Php
How do I integrate Prometheus metrics into a Laravel application with minimal setup?
Use Composer to install the package (`composer require promphp/prometheus_client_php`), then bootstrap the `CollectorRegistry` in your `AppServiceProvider`. For HTTP metrics, add middleware to track request durations, and expose metrics via a `/metrics` endpoint. Laravel’s service container makes global access easy.
Which Laravel versions and PHP versions are supported by this package?
The package requires PHP 8.2+ and works with Laravel 9 or 10. Ensure your Laravel app aligns with these PHP requirements, as older versions (e.g., Laravel 8 with PHP 8.1) may cause compatibility issues.
Can I use this package for Laravel queue workers or cron jobs?
Yes, but you’ll need a shared storage adapter like Redis or APCu to aggregate metrics across worker processes. Redis is recommended for production due to its scalability and persistence, while APCu is simpler for single-server setups.
How do I automatically track HTTP request metrics (e.g., response time, status codes) in Laravel?
Create middleware that records start time, increments counters for status codes, and observes request durations with a histogram. Register the middleware in `app/Http/Kernel.php` to apply it globally. Example: `response_time_seconds->observe($duration, ['method' => $request->method()]).`
What’s the best storage backend for production: Redis, APCu, or InMemory?
Redis is the safest choice for production, especially in multi-server or high-cardinality environments. APCu is lightweight but risks memory bloat with many metrics. InMemory is only suitable for single-process scripts or testing.
How do I expose metrics for Prometheus to scrape?
Add a route like `Route::get('/metrics', [MetricsController::class, 'render'])` and use the `RenderTextFormat` class to output Prometheus exposition format. Ensure your Prometheus server targets this endpoint (e.g., `scrape_configs: [targets: ['laravel-app:8000/metrics']]`).
Are there performance concerns with histograms or summaries in Laravel?
Histograms and summaries have higher overhead than counters/gauges due to bucket calculations. Benchmark under load—if using Redis, ensure it’s configured with sufficient memory. For high-throughput apps, limit bucket granularity or use sampling.
Can I use this package with Laravel’s queue jobs to track execution time?
Yes, decorate your jobs with a trait or use job events to record start/end times. For example, observe a histogram with `job_execution_seconds->observe($duration, ['job' => $job->getJob()])`. Redis ensures metrics persist across worker restarts.
What alternatives exist for Prometheus metrics in Laravel if Redis isn’t available?
If Redis is unavailable, APCu is a lightweight alternative for single-server setups, but avoid it for high-cardinality metrics. For distributed systems, consider the `promphp/prometheus_push_gateway_php` companion library to push metrics to a central gateway.
How do I test Prometheus metrics locally before deploying to production?
Run a local Redis instance (e.g., via Docker) and configure the package to use it. Test by triggering HTTP requests, queue jobs, or CLI commands, then verify metrics appear in Prometheus (`prometheus -target=http://localhost/metrics`). Use tools like `curl` to check the `/metrics` endpoint.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin