PHPackages                             run-as-root/magento2-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. run-as-root/magento2-prometheus-exporter

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

run-as-root/magento2-prometheus-exporter
========================================

Magento2 Prometheus Exporter

3.2.6(4mo ago)69344.4k—8.3%23[5 issues](https://github.com/run-as-root/magento2-prometheus-exporter/issues)MITPHPCI failing

Since Jun 14Pushed 4mo ago10 watchersCompare

[ Source](https://github.com/run-as-root/magento2-prometheus-exporter)[ Packagist](https://packagist.org/packages/run-as-root/magento2-prometheus-exporter)[ Docs](https://github.com/run-as-root/magento2-prometheus-exporter)[ RSS](/packages/run-as-root-magento2-prometheus-exporter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (19)Versions (21)Used By (0)

Magento 2 Prometheus Exporter
=============================

[](#magento-2-prometheus-exporter)

[![pipeline status](https://camo.githubusercontent.com/9412daacf0bad427b2833e2b67c616fb9056317311c3c8c4292a2c2662313b67/68747470733a2f2f6769746c61622e636f6d2f72756e5f61735f726f6f742f6d6167656e746f322d70726f6d6574686575732d6578706f727465722f6261646765732f6d61737465722f706970656c696e652e737667)](https://gitlab.com/run_as_root/magento2-prometheus-exporter/commits/master)

A comprehensive Magento 2 module that exposes essential Magento metrics in Prometheus format, enabling powerful monitoring and observability for your e-commerce platform.

🚀 Features
----------

[](#-features)

- **📊 Rich Metrics Collection**: Monitors orders, products, customers, CMS content, cron jobs, indexers, and more
- **🔧 Configurable Metrics**: Enable/disable specific metrics through Magento admin interface
- **🔐 Secure Access**: Bearer token authentication support to protect your metrics endpoint
- **⚡ Performance Optimized**: Efficient cron-based data aggregation to minimize performance impact
- **🎯 Prometheus Ready**: Native Prometheus format output for seamless integration
- **🔌 Extensible Architecture**: Easy to add custom metrics with clean interfaces

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [Installation](#-installation)
- [Configuration](#-configuration)
- [Prometheus Setup](#-prometheus-setup)
- [Available Metrics](#-available-metrics)
- [Security](#-security)
- [Custom Metrics](#-custom-metrics)
- [CLI Commands](#-cli-commands)
- [Architecture](#-architecture)
- [Troubleshooting](#-troubleshooting)
- [Contributing](#-contributing)
- [License](#-license)

📦 Installation
--------------

[](#-installation)

### Requirements

[](#requirements)

- Magento 2.3.x or higher
- PHP 7.4 or higher
- Composer

### Install via Composer

[](#install-via-composer)

```
composer require run-as-root/magento2-prometheus-exporter
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush
```

### Verify Installation

[](#verify-installation)

After installation, your metrics endpoint will be available at:

```
https://your-magento-store.com/metrics

```

⚙️ Configuration
----------------

[](#️-configuration)

### Admin Configuration

[](#admin-configuration)

Navigate to **Stores → Configuration → Prometheus → Metric Configuration** to:

- Enable/disable specific metric collectors
- Configure authentication settings
- Set collection intervals
- Manage metric labels and groupings

### Cron Configuration

[](#cron-configuration)

The module automatically registers a cron job that runs every minute to aggregate metrics. The job uses a dedicated cron group: `run_as_root_prometheus_metrics_aggregator`.

🎯 Prometheus Setup
------------------

[](#-prometheus-setup)

### Basic Configuration

[](#basic-configuration)

Add the following scrape configuration to your `prometheus.yml`:

```
scrape_configs:
  - job_name: 'magento-2'
    scrape_interval: 5m
    scrape_timeout: 60s
    metrics_path: /metrics
    static_configs:
      - targets:
          - 'your-magento-store.com'
```

### With Authentication

[](#with-authentication)

For production environments, secure your metrics endpoint:

```
scrape_configs:
  - job_name: 'magento-2'
    scrape_interval: 5m
    scrape_timeout: 60s
    metrics_path: /metrics
    authorization:
      type: 'Bearer'
      credentials: 'your-bearer-token-here'
    static_configs:
      - targets:
          - 'your-magento-store.com'
```

### Advanced Configuration with Labels

[](#advanced-configuration-with-labels)

```
scrape_configs:
  - job_name: 'magento-2'
    scrape_interval: 5m
    scrape_timeout: 60s
    metrics_path: /metrics
    authorization:
      type: 'Bearer'
      credentials: 'your-bearer-token-here'
    static_configs:
      - targets:
          - 'your-magento-store.com'
    relabel_configs:
      - source_labels: [__address__]
        target_label: instance
        replacement: 'magento-production'
```

📊 Available Metrics
-------------------

[](#-available-metrics)

### Order Metrics

[](#order-metrics)

MetricTypeLabelsDescription`magento_orders_count_total`gauge`status`, `store_code`Total count of orders by status and store`magento_orders_amount_total`gauge`status`, `store_code`Total revenue by order status and store`magento_order_items_count_total`gauge`status`, `store_code`Total count of order items### Product &amp; Catalog Metrics

[](#product--catalog-metrics)

MetricTypeLabelsDescription`magento_products_by_type_count_total`gauge`product_type`Count of products by type (simple, configurable, etc.)`magento_catalog_category_count_total`gauge`status`, `menu_status`, `store_code`Count of categories by status### EAV &amp; Attribute Metrics

[](#eav--attribute-metrics)

MetricTypeLabelsDescription`magento_eav_attribute_count_total`gauge-Total count of EAV attributes`magento_eav_attribute_options_above_recommended_level_total`gauge-Count of attributes with more than 100 options (performance risk)### Customer Metrics

[](#customer-metrics)

MetricTypeLabelsDescription`magento_customer_count_total`gauge`store_code`Total count of registered customers### Content Metrics

[](#content-metrics)

MetricTypeLabelsDescription`magento_cms_block_count_total`gauge`store_code`Count of CMS blocks`magento_cms_page_count_total`gauge`store_code`Count of CMS pages### System Health Metrics

[](#system-health-metrics)

MetricTypeLabelsDescription`magento_cronjob_count_total`gauge`status`, `job_code`Count of cron jobs by status`magento_cronjob_broken_count_total`gauge-Count of broken cron jobs`magento_indexer_backlog_count_total`gauge`title`Count of items in indexer backlog### Infrastructure Metrics

[](#infrastructure-metrics)

MetricTypeLabelsDescription`magento_store_count_total`gauge`status`Count of stores by status`magento_website_count_total`gauge-Total count of websites`magento_shipments_count_total`counter`source`, `store_code`Count of shipments created🔐 Security
----------

[](#-security)

### Authentication Setup

[](#authentication-setup)

1. **Generate Bearer Token**: Navigate to Magento Admin → System → Integrations
2. **Create New Integration**: Set up API access with appropriate permissions
3. **Configure Token**: Use the generated access token in your Prometheus configuration

### Best Practices

[](#best-practices)

- Always use HTTPS for metrics endpoints in production
- Regularly rotate authentication tokens
- Restrict access to metrics endpoint via firewall rules
- Monitor access logs for unusual activity

### IP Whitelisting

[](#ip-whitelisting)

Consider restricting access to your Prometheus server IPs:

```
location /metrics {
    allow 10.0.0.0/8;     # Your Prometheus server
    allow 172.16.0.0/12;  # Internal network
    deny all;
    try_files $uri $uri/ /index.php?$args;
}
```

🔧 Custom Metrics
----------------

[](#-custom-metrics)

### Creating a Custom Metric Aggregator

[](#creating-a-custom-metric-aggregator)

1. **Implement the Interface**:

```
