prometheus-bundle
prometheus-bundle copied to clipboard
How to implement collection of metrics
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?
@rnijveld
This is detailed in the README:
- You need to specify the collectors in your
tweede_golf_prometheusconfiguration section. - At either an action or an event listener you need to get the collector from the registry and
observeorinc. - You can add this bundle to your routing and
/metricswill be served by the MetricsController, which willcollectall the data from thecollectorsregistered to the registry and present it as Prometheus expects.
@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?