PHPackages                             saschahemleb/laravel-prometheus-exporter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. saschahemleb/laravel-prometheus-exporter

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

saschahemleb/laravel-prometheus-exporter
========================================

A Prometheus exporter for Laravel

v2.0.1(1y ago)14.4kMITPHPPHP ^7.2.5 || ^8.0 || ^8.1

Since Feb 11Pushed 1y agoCompare

[ Source](https://github.com/saschahemleb/laravel-prometheus-exporter)[ Packagist](https://packagist.org/packages/saschahemleb/laravel-prometheus-exporter)[ RSS](/packages/saschahemleb-laravel-prometheus-exporter/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (5)Dependencies (8)Versions (8)Used By (0)

Laravel Prometheus Exporter
===========================

[](#laravel-prometheus-exporter)

A prometheus exporter package for Laravel.

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Introduction
------------

[](#introduction)

Prometheus is a time-series database with a UI and sophisticated querying language (PromQL) that can scrape metrics, counters, gauges and histograms over HTTP.

This package is a wrapper bridging [promphp/prometheus\_client\_php](https://github.com/promphp/prometheus_client_php) into Laravel.

Installation
------------

[](#installation)

Install the package via composer

```
composer require saschahemleb/laravel-prometheus-exporter
```

Please see below for instructions on how to enable metrics on Application routes.

Configuration
-------------

[](#configuration)

The package has a default configuration which uses the following environment variables.

```
PROMETHEUS_NAMESPACE=app

PROMETHEUS_METRICS_ROUTE_ENABLED=true
PROMETHEUS_METRICS_ROUTE_PATH=metrics
PROMETHEUS_COLLECT_FULL_SQL_QUERY=true
PROMETHEUS_STORAGE_ADAPTER=memory

PROMETHEUS_REDIS_CONNECTION=default
PROMETHEUS_REDIS_PREFIX=PROMETHEUS_

```

To customize the configuration values you can either override the environment variables above (usually this is done in your application's `.env` file), or you can publish the included [prometheus.php](config/prometheus.php)to `config/prometheus.php`.

```
$ php artisan vendor:publish --provider "Saschahemleb\\LaravelPrometheusExporter\\PrometheusServiceProvider"
```

Metrics
-------

[](#metrics)

The package allows you to observe metrics on:

- Application routes. Metrics on request method, request path and status code.
- SQL queries. Metrics on SQL query and query type.

In order to observe metrics in application routes (the time between a request and response), you should register the following middleware in your application's `app/Http/Kernel.php`:

```
protected $middleware = [
    \Saschahemleb\LaravelPrometheusExporter\Http\Middleware\ObserveResponseTime::class,
    // [...]
];
```

The labels exported are

```
[
    'method',
    'route',
    'status_code',
]
```

SQL metrics are observed ootb. The labels exported are

```
[
    'query',
    'query_type',
]
```

Note: you can disable logging the full query by turning off the configuration of `PROMETHEUS_COLLECT_FULL_SQL_QUERY`.

### Storage Adapters

[](#storage-adapters)

The storage adapter is used to persist metrics across requests. The `memory` adapter is enabled by default, meaning data will only be persisted across the current request.

We recommend using the `redis` or `apc` adapter in production environments. Of course your installation has to provide a Redis or APC implementation.

The `PROMETHEUS_STORAGE_ADAPTER` environment variable is used to specify the storage adapter.

Exporting Metrics
-----------------

[](#exporting-metrics)

The package adds a `/metrics` endpoint, enabled by default, which exposes all metrics gathered by collectors.

This can be turned on/off using the `PROMETHEUS_METRICS_ROUTE_ENABLED` environment variable, and can also be changed using the `PROMETHEUS_METRICS_ROUTE_PATH` environment variable.

Collectors
----------

[](#collectors)

A collector is a class, implementing the [CollectorInterface](src/CollectorInterface.php), which is responsible for collecting data for one or many metrics.

Please see the [Example](#Collector) included below.

You can auto-load your collectors by adding them to the `collectors` array in the `prometheus.php` config.

Examples
--------

[](#examples)

### Collector

[](#collector)

This is an example collector implementation:

```
