Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

How to implement collection of metrics #5

Open
estahn opened this issue Feb 12, 2019 · 3 comments
Open

How to implement collection of metrics #5

estahn opened this issue Feb 12, 2019 · 3 comments

Comments

@estahn
Copy link

estahn commented Feb 12, 2019

I'm not quite sure how to implement the collection of metrics. Do I create a class that extends one of the collectors (e.g. Counter)? Or can I create a plain class injecting the CollectorRegistry and that is somehow getting called when /metrics is getting hit?

@estahn
Copy link
Author

estahn commented Feb 13, 2019

@rnijveld

@Wassasin
Copy link
Contributor

This is detailed in the README:

  1. You need to specify the collectors in your tweede_golf_prometheus configuration section.
  2. At either an action or an event listener you need to get the collector from the registry and observe or inc.
  3. You can add this bundle to your routing and /metrics will be served by the MetricsController, which will collect all the data from the collectors registered to the registry and present it as Prometheus expects.

@estahn
Copy link
Author

estahn commented Feb 28, 2019

@Wassasin I understand the general concept. I just don't see how an action is being executed.

I created a folder src/Metrics which contains a file CoffeeMetrics.php.The file looks like this:

<?php

namespace App\Metrics;

class CoffeeMetrics
{
    public function __construct(CollectorRegistry $collectorRegistry, Connection $connection)
    {
        $coffees = $connection->exec('select count(*) coffees');

        $coffeesTotal = $collectorRegistry->getCounter('coffees_total');
        $coffeesTotal->inc();
    }
}

How do I reference this so its being picked up?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants