An example repository showing how to instrument a Laravel application, so it creates Prometheus metrics.
There are a few elements:
- Creates a
/metrics
endpoint for Prometheus to scrape - Stores metrics in Redis so they persist long enough for Prometheus to get when periodically calling the
/metrics
endpoint - Generates user (programmer) defined metrics
In this specific repository, we use the promphp/prometheus_client_php
composer package in Laravel.
Files to check out:
app/Providers/PrometheusServiceProvider
- registered inconfig/app.php
, creates a singleton for the Prometheus libraryCollectorRegistry
class (the main one you use for that library)- Also sets up Redis to persist metrics
app/Prometheus
- classes corresponding to metrics created in the app, along with theProm
facadeapp/Http/Controllers/Metrics.php
- The controller that generates metrics output for Prometheus to read at the/metrics
route, registered inroutes/web.php
app/Console/Commands/GenerateMetricsCommand.php
- A console command, called every few minutes by the scheduler. This generate some metrics with some randomness, simulating what might be real-ish metrics.
The metrics this app collects is related to the corresponding article found at https://fly.io/laravel-bytes.