Weave Code
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

Prometheus Client Laravel Package

dbstudios/prometheus-client

Lightweight Prometheus client for PHP. Create a CollectorRegistry, choose a storage adapter (Redis, Filesystem, APCu), then register and use counters, gauges, and histograms. Retrieve collectors by name with typed helpers for safer access.

View on GitHub
Deep Wiki
Context7

A client library for the Prometheus monitoring system

Frequently asked questions about Prometheus Client
How do I install and set up this Prometheus client in a Laravel project?
Run `composer require dbstudios/prometheus-client` to install. Initialize a `CollectorRegistry` and configure an adapter (Redis, filesystem, or APCu) in your `AppServiceProvider` or a dedicated service class. Register collectors like counters, gauges, or histograms, then access them globally via the registry.
Does this package work with Laravel 9+ (PHP 8.0+)?
The package officially supports PHP 7.3+, but Laravel 9+ (PHP 8.0+) may require minor adjustments or a fork for full compatibility. Test thoroughly, especially if using strict typing or new PHP features. Check for PHP 8.1+ compatibility if needed.
Can I use this for tracking HTTP request metrics in Laravel?
Yes, instrument middleware like `HandleIncomingRequest` to track request counts, latency, or errors. Register a histogram for timing metrics (e.g., `observe()` with request duration) and counters for request volumes. Expose metrics via `/metrics` endpoint using the adapter of your choice.
What are the best adapters for production Laravel deployments?
For distributed Laravel apps, use **Redis** for low-latency, shared metrics across instances. For single-server setups, **filesystem** is simplest, while **APCu** offers in-memory speed but no persistence. Benchmark under your expected load to avoid bottlenecks.
How do I expose Prometheus metrics to a scraping endpoint?
Create a Laravel route (e.g., `GET /metrics`) that outputs the adapter’s stored metrics. For Redis/filesystem, use the adapter’s `scrape()` method or serialize data manually. Ensure the endpoint is accessible to your Prometheus server (e.g., `scrape_configs` in `prometheus.yml`).
Are there alternatives to this package for Laravel Prometheus support?
Consider `prometheus/client_php` (official PHP client) for broader compatibility or Spatie’s monitoring packages for Laravel-specific integrations. This package is lighter but lacks Laravel-native features like service container binding. Evaluate based on your need for manual vs. automated instrumentation.
How do I handle dynamic labels (e.g., per-user metrics) without rigid definitions?
Define a base label set (e.g., `user_id`, `service`) and use wildcards or consistent naming for dynamic values. Avoid over-labeling; Prometheus supports dynamic labels, but excessive cardinality can strain storage. Test with realistic workloads to balance flexibility and performance.
Is this package actively maintained? Should I fork it for Laravel 9+?
The package has minimal recent activity (last release in 2020). Forking is advisable for PHP 8.1+ or Laravel-specific features (e.g., service container integration). Monitor for Prometheus spec changes and apply fixes upstream if possible. Consider contributing to revive the project.
How do I test metric collection in Laravel’s testing environment?
Mock the `CollectorRegistry` and adapters in PHPUnit tests. Verify collector methods (e.g., `increment()`, `observe()`) are called with expected values. For integration tests, use a temporary Redis instance or filesystem directory. Avoid testing the Prometheus server directly—focus on metric emission.
What’s the performance impact of using Redis or filesystem adapters?
Redis adds network latency (~1–10ms per operation) but scales well for distributed Laravel apps. Filesystem is slower (~10–100ms per write) but works for low-volume metrics. APCu is fastest (in-memory) but loses data on restart. Benchmark with your expected metric volume (e.g., 1K–10K ops/sec).
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor