acseo/sylius-prometheus-metrics-plugin

Sylius Prometheus Metrics Plugin

v1.0 2023-06-14 07:58 UTC

This package is auto-updated.

Last update: 2024-04-20 16:39:31 UTC


README

ACSEO

Sylius Prometheus Metrics
68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616373656f2f73796c6975732d70726f6d6574686575732d6d6574726963732d706c7567696e2e737667 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616373656f2f73796c6975732d70726f6d6574686575732d6d6574726963732d706c7567696e2e737667

Features

Observability

We use the artprima/prometheus-metrics-bundle (https://github.com/artprima/prometheus-metrics-bundle) bundle to collect metrics in the Prometheus format, which can then be used to build a dashboard with Grafana. These metrics are visible at the /metrics/prometheus URL of the website.

Default metrics are generated. It is possible to create custom metrics to track "Business" data, such as the number of created orders or the order amount.

68747470733a2f2f70726f6d6574686575732e696f2f6173736574732f67726166616e615f70726f6d6574686575732e706e67

Installation

  1. Run $ composer require acseo/sylius-prometheus-metrics-plugin.

  2. Add these few lines to the config/state_machine/sylius_payment.yaml

winzou_state_machine:
   sylius_payment:
      callbacks:
         after:
            sylius_order_items_complete_collector:
               on: 'complete'
               do: ['@metrics.order_collector', 'incrementPrometheusCounters']
               args: ["object.getOrder()"]

Installation without Symfony Flex

  1. Run $ composer require acseo/sylius-prometheus-metrics-plugin.

  2. Enable the plugin in bundles.php

<?php
// config/bundles.php

return [
    // ...
    Artprima\PrometheusMetricsBundle\ArtprimaPrometheusMetricsBundle::class => ['all' => true],
    Acseo\SyliusPrometheusMetricsPlugin\SyliusPrometheusMetricsPlugin::class => ['all' => true],
];
  1. Add this file config/packages/prometheus_metrics.yaml
artprima_prometheus_metrics:
    namespace: myapp
    storage: '%env(PROM_METRICS_DSN)%'

    ignored_routes:
        - prometheus_bundle_prometheus
        - _wdt

    # used to disable default application metrics
    #disable_default_metrics: false

    # Recommended to disable default metrics from promphp/prometheus_client_php
    # see https://github.com/PromPHP/prometheus_client_php/issues/62
    disable_default_promphp_metrics: true

    # used to enable console metrics
    #enable_console_metrics: false

when@test:
    artprima_prometheus_metrics:
        storage: in_memory
  1. Add the metrics routes config/routes/metrics.yaml
app_metrics:
    resource: '@ArtprimaPrometheusMetricsBundle/Resources/config/routing.xml'
  1. Add environment variables
###> artprima/prometheus-metrics-bundle ###
PROM_METRICS_DSN=apcu
###< artprima/prometheus-metrics-bundle ###