artprima / prometheus-metrics-bundle

Symfony 5/6 Prometheus Metrics Bundle
MIT License
133 stars 29 forks source link

Is there any way how to disable default metrics? #41

Closed InboxViktorV closed 3 years ago

InboxViktorV commented 3 years ago

At the moment the easiest way is:

services.yaml

Artprima\PrometheusMetricsBundle\Metrics\AppMetrics:
        class: App\Metrics\UnregisterDefaultMetrics

UnregisterDefaultMetrics.php

<?php

declare(strict_types=1);

namespace App\Metrics;

use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;

class UnregisterDefaultMetrics extends \Artprima\PrometheusMetricsBundle\Metrics\AppMetrics
{
    public function collectRequest(RequestEvent $event): void
    {
        return;
    }

    public function collectResponse(TerminateEvent $event): void
    {
        return;
    }

    public function collectStart(RequestEvent $event): void
    {
        return;
    }
}

But maybe there is more elegant way to do that?

Btw. Definition::clearTags() not works, cause default metrics added to MetricsCollectorRegistry before tag is removed Btw2. Redefine also doesn't work:

Artprima\PrometheusMetricsBundle\Metrics\AppMetrics:
        class: App\Metrics\AppMetrics

In this case custom metrics will be called twice

denisvmedia commented 3 years ago

It is as easy as

artprima_prometheus_metrics:
    # ...
    disable_default_metrics: true
InboxViktorV commented 3 years ago

It is as easy as

artprima_prometheus_metrics:
    # ...
    disable_default_metrics: true

Ohhh:sweat_smile: It is added in new version. Ok, thanks)