Prometheus endpoint
The scrape route serves Metrics::export() in the Prometheus text format.
| Property | Value |
|---|---|
| Method | GET (and HEAD) |
| URI | metrics.prometheus.path, metrics by default |
| Name | metrics.prometheus |
| Middleware | metrics.prometheus.middleware, none by default |
| Controller | Nwidart\Metrics\Http\PrometheusController (invokable) |
The package registers the route when both are true:
metrics.enabledistrue;metrics.prometheus.enabledistrue.
With cached routes (php artisan route:cache), the package registers no route. The cached routes hold the route as it was when the cache was built.
The controller can serve under another route:
use Nwidart\Metrics\Http\PrometheusController;
Route::get('/internal/metrics', PrometheusController::class)->middleware('auth.basic');Responses
Section titled “Responses”| Case | Status | Content type | Body |
|---|---|---|---|
| Export read | 200 |
text/plain; version=0.0.4; charset=utf-8 |
The samples |
| Metrics disabled, with the controller on a route of your own, or with routes cached while metrics were on | 200 |
text/plain; version=0.0.4; charset=utf-8 |
Empty |
| The store cannot be built or read | 503 |
text/plain; charset=utf-8 |
The metrics store cannot be read. |
On a 503, the exception is passed to report(). While metrics are disabled, the package registers no route, so its own path answers 404.
The resource of the export is empty, so no resource attribute becomes a label.
Format
Section titled “Format”The text format is version 0.0.4, rendered by Nwidart\MetricsStore\Prometheus\PrometheusTextFormat. It follows the OpenTelemetry Prometheus and OpenMetrics compatibility specification.
- Characters that Prometheus does not allow become
_. Repeated_become one. - The unit is added as a word:
sadds_seconds,Byadds_bytes. An annotation such as{request}adds nothing. The unit1adds_ratioto a gauge, and nothing to other types. - A monotonic sum ends in
_total, once. - The
# HELPline holds the description of the instrument. - Metric families are sorted by name.
| OpenTelemetry metric | Prometheus metric |
|---|---|
http.server.request.duration (s) |
http_server_request_duration_seconds |
laravel.exceptions (counter) |
laravel_exceptions_total |
system.filesystem.usage (By) |
system_filesystem_usage_bytes |
| OpenTelemetry data | Prometheus type |
|---|---|
| Monotonic sum (counter) | counter |
| Non-monotonic sum (up-down counter) | gauge |
| Gauge | gauge |
| Histogram | histogram, with cumulative le buckets, _sum and _count |
Labels
Section titled “Labels”- Each attribute becomes a label. Characters that Prometheus does not allow become
_. A boolean becomestrueorfalse. otel_scope_nameholds the name of the meter. For the built-in metrics, it isnwidart/laravel-metrics.otel_scope_versionholds the version of the meter, when it has one.- The labels of
metrics.prometheus.labelsare added to every sample. An attribute of the same name wins over them. - Labels are sorted by name, with
lelast.
Left out
Section titled “Left out”- Delta metrics.
- A metric whose name another metric of another type already uses.
- A repeated sample.
Example
Section titled “Example”# HELP http_server_request_duration_seconds Duration of HTTP server requests.# TYPE http_server_request_duration_seconds histogramhttp_server_request_duration_seconds_bucket{http_request_method="GET",http_response_status_code="200",http_route="/orders",network_protocol_version="1.1",otel_scope_name="nwidart/laravel-metrics",url_scheme="https",le="0.005"} 0...The scrape request is recorded in http.server.request.duration like any other request, with http.route set to the route URI, unless ignore_routes matches it.