spatie/laravel-prometheus
Export Laravel app metrics to Prometheus via a /prometheus endpoint. Register custom gauges/counters with simple callbacks, use built-in queue and Horizon metrics, and optionally secure the endpoint. Ideal for scraping by Prometheus and charting in Grafana.
config/prometheus.php), with zero runtime overhead by default.prometheus-operator) or bare-metal setups.prometheus:queue middleware).prometheus:http middleware).spatie/laravel-activitylog for query metrics.Illuminate\Support\Facades\Route changes).laravel_http_request_duration_seconds) and retention policies.prometheus:disable to validate.http_requests_total > 1000)?user_id labels) may inflate Prometheus storage costs.prometheus-blackbox-exporter)?prometheus-operator + ServiceMonitor CRDs).Phase 1: Core Metrics (Low Risk)
composer require spatie/laravel-prometheus.config/prometheus.php with default metrics (HTTP, queues, DB).prom/prometheus Docker image).laravel-prometheus dashboard.Phase 2: Custom Instrumentation (Medium Risk)
increment('api.calls.success')).Phase 3: Alerting & Scaling (High Impact)
error_rate > 0.1).Route::middleware() syntax).prometheus/client_php, which is stable but may need updates for new Prometheus features (e.g., histogram buckets).spatie/laravel-query-logger or manual instrumentation.| Step | Task | Dependencies | Owner |
|---|---|---|---|
| 1 | Install package + configure config/prometheus.php |
Laravel app | Backend |
| 2 | Deploy Prometheus server (e.g., Docker/K8s) | Network access | DevOps/SRE |
| 3 | Validate core metrics (HTTP, queues) | Prometheus endpoint | QA |
| 4 | Add custom metrics (e.g., business KPIs) | Domain knowledge | Product/Backend |
| 5 | Integrate Grafana dashboards | Prometheus data source | Observability |
| 6 | Set up Alertmanager rules | SLOs/SLIs | SRE |
| 7 | Optimize retention/storage | Cost constraints | DevOps |
composer update.config/prometheus.php; Gitops-friendly.http://laravel-app/metrics).XHProf to isolate instrumentation overhead.sum by (route)).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Prometheus server down | Metrics unavailable | Deploy high-availability Prometheus (HA setup). |
| Network partition (Laravel → Prometheus) | Missing scrape data | Set scrape timeout (e.g., 10s) and retry logic. |
| Over-instrumentation | High cardinality → storage costs | Enforce metric naming standards (e.g., no dynamic labels). |
| Laravel app crash | No new metrics | Use Prometheus’ scrape_timeout to avoid flapping. |
| Custom metric misconfiguration |
How can I help you explore Laravel packages today?