simbi/laravel-metrics-exporter

Prometheus metrics exporter for Laravel applications following RED/USE methodology

Maintainers

Package info

github.com/simbiosesocial/laravel-metrics-exporter

pkg:composer/simbi/laravel-metrics-exporter

Statistics

Installs: 12

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-03-07 01:10 UTC

This package is auto-updated.

Last update: 2026-03-07 01:36:12 UTC


README

Prometheus metrics exporter for Laravel applications following RED/USE methodology.

Requirements

  • PHP 8.2+
  • Laravel 10.x or 11.x

Installation

composer require simbi/laravel-metrics-exporter

The package uses Laravel's auto-discovery, so the service provider will be registered automatically.

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=metrics-exporter-config

Set the application name in your .env:

PROMETHEUS_APP_NAME=my-app-name

Environment Variables

Variable Default Description
METRICS_EXPORTER_ENABLED true Enable/disable metrics exporter
PROMETHEUS_APP_NAME app Application name for the app label
METRICS_EXPORTER_ENV_VAR APP_ENV Environment variable for the environment label
METRICS_EXPORTER_PATH metrics URL path for the metrics endpoint
PROMETHEUS_CACHE_STORE file Cache store for persisting metrics

Feature Flags

You can enable/disable specific collectors:

// config/metrics-exporter.php
'features' => [
    'http' => true,    // HTTP request metrics (RED)
    'queue' => true,   // Queue job metrics
    'process' => true, // Process metrics (USE)
],

Metrics Exposed

HTTP Metrics (RED)

  • http_requests_total - Counter of total HTTP requests
  • http_request_duration_seconds - Histogram of request durations
  • http_requests_in_flight - Gauge of current in-flight requests

Queue Metrics

  • jobs_processed_total - Counter of processed jobs
  • jobs_failed_total - Counter of failed jobs
  • jobs_processing_duration_seconds - Histogram of job processing durations

Process Metrics (USE)

  • process_cpu_seconds_total - Total CPU time
  • process_resident_memory_bytes - Resident memory size
  • process_open_fds - Open file descriptors
  • process_start_time_seconds - Process start time

Manual Recording (AMQP/RabbitMQ)

For consumers that don't use Laravel's Queue system:

use Simbi\MetricsExporter\Support\MetricsRecorder;

$recorder = app(MetricsRecorder::class);
$startTime = microtime(true);

try {
    $this->processMessage($message);
    $recorder->jobProcessed('emails', 'SendWelcomeEmail', microtime(true) - $startTime);
} catch (Throwable $e) {
    $recorder->jobFailed('emails', 'SendWelcomeEmail');
    throw $e;
}

Running Tests

Clone the repository and run tests:

Local (requires PHP 8.2+)

git clone git@github.com:simbiosesocial/laravel-metrics-exporter.git
cd laravel-metrics-exporter
composer install
composer test

Using Docker

git clone git@github.com:simbiosesocial/laravel-metrics-exporter.git
cd laravel-metrics-exporter

# Run tests
docker compose run --rm tests

# Interactive shell for debugging
docker compose run --rm shell

# Rebuild after changing dependencies
docker compose build --no-cache

Contributing

This is an internal package for Simbi Social applications.

License

Proprietary - Simbi Social