PHPackages                             liveintent/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. liveintent/laravel-prometheus-exporter

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

liveintent/laravel-prometheus-exporter
======================================

Prometheus exporter for laravel metrics.

v1.4.1(4y ago)35.1k3MITPHPPHP ^7.4|^8.0

Since Apr 2Pushed 1y ago5 watchersCompare

[ Source](https://github.com/LiveIntent/laravel-prometheus-exporter)[ Packagist](https://packagist.org/packages/liveintent/laravel-prometheus-exporter)[ RSS](/packages/liveintent-laravel-prometheus-exporter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (10)Versions (10)Used By (0)

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

[](#laravel-prometheus-exporter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/236067ceb030ba3469cde6d3e222fffaf1ac478ce2cfd2ce317e06152be4ddc5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c697665696e74656e742f6c61726176656c2d70726f6d6574686575732d6578706f727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/liveintent/laravel-prometheus-exporter)[![GitHub Tests Action Status](https://camo.githubusercontent.com/656fc34a9536ac2f66b2c9d55434d417c0d62f38baa397af31d1a6c4b71fa8da/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c697665696e74656e742f6c61726176656c2d70726f6d6574686575732d6578706f727465722f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/liveintent/laravel-prometheus-exporter/actions?query=workflow%3ATests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a2e1d513ea7dcbf0b0aa35b8491ea7f566e6307cb4234a275e2520e4a9e6a542/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c697665696e74656e742f6c61726176656c2d70726f6d6574686575732d6578706f727465722f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/liveintent/laravel-prometheus-exporter/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/2db7ded75fe4fdbf1fa560e8e5d7bafda96ec7956cb64d5e1acc55e465acfab9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c697665696e74656e742f6c61726176656c2d70726f6d6574686575732d6578706f727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/liveintent/laravel-prometheus-exporter)

This is a Laravel package that automatically collects data and exposes a `/metrics` endpoint in your application which can then be scraped by [Prometheus](https://prometheus.io/).

For a full list of exported metrics, see [exporters](#exporters).

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

[](#installation)

You can install the package via composer:

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

Once installed run the following command to generate the `metrics` config file.

```
php artisan metrics:install
```

The package will auto-register itself.

Usage
-----

[](#usage)

The `metrics` config file contains a list of enabled exporters. Each exporter will collect data and store it in your configured data store.

### Storage

[](#storage)

The storage drivers currently supperted are redis, apc, and in-memory. You may adjust this value by setting the env `METRICS_STORAGE_DRIVER`.

The package uses the in-memory driver by default to help you get started, but you should change this as soon as you are ready as it's not useful for much beyond testing.

You will need the appropriate `pecl` extension installed ([apc](https://pecl.php.net/package/APCU) or [php-redis](https://pecl.php.net/package/redis)).

If you need to clear the storage, you may do so with:

```
php artisan metrics:clear
```

### Exporters

[](#exporters)

#### Request Duration Historam Exporter - `http_request_duration_seconds_bucket`

[](#request-duration-historam-exporter---http_request_duration_seconds_bucket)

This will export histogram data for request duration.

##### Example

[](#example)

```
Exporters\RequestDurationHistogramExporter::class => [
    'enabled' => env('EXPORT_REQUEST_DURATION_HISTOGRAM', true),
    'options'
        'buckets' => [
            5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200
        ],
    ],
],
```

##### Labels

[](#labels)

namedescriptionexampleservicename of the servicemy-amazing-apienvironmentthe environment`qa`, `prod`, etcresponse\_codethe http response code`200`, `400`, etcmethodthe http method`GET`, `POST`, etcpaththe uri of the request`/`, `/posts`, etc#### Request Memory Usage Historam Exporter - `http_request_memory_usage_bytes`

[](#request-memory-usage-historam-exporter---http_request_memory_usage_bytes)

This will export histogram data for request memory usage.

##### Example

[](#example-1)

```
Exporters\RequestMemoryUsageHistogramExporter::class => [
    'enabled' => env('EXPORT_MEMORY_USAGE_HISTOGRAM', true),
    'options'
        'buckets' => [
            5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200
        ],
    ],
],
```

##### Labels

[](#labels-1)

namedescriptionexampleservicename of the servicemy-amazing-apienvironmentthe environment`qa`, `prod`, etccodethe http response code`200`, `400`, etcmethodthe http method`GET`, `POST`, etcpaththe uri of the request`/`, `/posts`, etc#### Job Processing Time Historam Exporter - `job_process_time_seconds_bucket`

[](#job-processing-time-historam-exporter---job_process_time_seconds_bucket)

This will export histogram data for job execution duration.

##### Example

[](#example-2)

```
Exporters\JobProcessTimeHistogramExporter::class => [
    'enabled' => env('EXPORT_JOB_PROCESS_TIME_HISTOGRAM', true),
    'options'
        'buckets' => [
            0.1, .3, .5, .7, 1, 2, 3, 4, 5, 10, 30, 40, 60,
        ],
    ],
],
```

##### Labels

[](#labels-2)

namedescriptionexampleservicename of the servicemy-amazing-apienvironmentthe environment`qa`, `prod`, etcnamethe classname of the job`App\\Jobs\\ProcessPayment`statusthe job status`procesed`, `failed`#### Job Wait Time Historam Exporter - `job_wait_time_seconds_bucket`

[](#job-wait-time-historam-exporter---job_wait_time_seconds_bucket)

This will export histogram data for the time a job had to wait on the queue.

**Note:** This exporter relies on [Laravel Horizon](https://laravel.com/docs/master/horizon).

##### Example

[](#example-3)

```
Exporters\JobWaitTimeHistogramExporter::class => [
    'enabled' => env('EXPORT_JOB_WAIT_TIME_HISTOGRAM', true),
    'options'
        'buckets' => [
            0.1, .3, .5, .7, 1, 2, 3, 4, 5, 10, 30, 40, 60,
        ],
    ],
],
```

##### Labels

[](#labels-3)

namedescriptionexampleservicename of the servicemy-amazing-apienvironmentthe environment`qa`, `prod`, etcnamethe classname of the job`App\\Jobs\\ProcessPayment`#### Query Duration Historam Exporter - `db_query_time_seconds_bucket`

[](#query-duration-historam-exporter---db_query_time_seconds_bucket)

This will export histogram data for query execution times.

##### Example

[](#example-4)

```
Exporters\QueryDurationHistogramExporter::class => [
    'enabled' => env('EXPORT_QUERY_DURATION_HISTOGRAM', true),
    'options'
        'buckets' => [
            5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200
        ],
    ],
],
```

##### Labels

[](#labels-4)

namedescriptionexampleservicename of the servicemy-amazing-apienvironmentthe environment`qa`, `prod`, etcsqlthe sql query`SELECT * FROM `users` `### Writing New Exporters

[](#writing-new-exporters)

You may also write your own exporter. You only need to implement two methods, `register` and `export`.

The following example increments a counter every time the `/` route is visited.

```
