artprima / prometheus-metrics-bundle

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

Documentation: default metrics #32

Closed luispabon closed 3 years ago

luispabon commented 3 years ago

Just trying this bundle out now. Upon installation on an api-platorm project via symfony flex recipe, the only output I'm getting from the prometheus endpoint is:

~ http http://localhost:2000/metrics/prometheus   
HTTP/1.1 200 OK
Cache-Control: max-age=0, must-revalidate, private
Connection: keep-alive
Content-Type: text/plain; version=0.0.4; charset=UTF-8
Date: Wed, 06 Jan 2021 12:02:28 GMT
Expires: Wed, 06 Jan 2021 12:02:28 GMT
Link: <http://localhost:2000/api/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"
Server: nginx/1.19.6
Transfer-Encoding: chunked
X-Debug-Token: bd92a7
X-Debug-Token-Link: http://localhost:2000/_profiler/bd92a7
X-Robots-Tag: noindex

# HELP php_info Information about the PHP environment.
# TYPE php_info gauge
php_info{version="7.4.13"} 1

I'm quite confused on what metrics the bundle collects by default (if any), as the docs don't really have anything to say on that particular subject.

denisvmedia commented 3 years ago

Do you have

    Artprima\PrometheusMetricsBundle\ArtprimaPrometheusMetricsBundle::class => ['all' => true],

in your config/bundles.php?

As of the docs, you are right, I need to improve them to give more information on what are the default metrics.

luispabon commented 3 years ago

Yes, correct. The symfony recipe works fine. It wasn't collecting anything because of my config:

artprima_prometheus_metrics:
  namespace: my-api
  type: apcu
  ignored_routes:
    - prometheus_bundle_prometheus
    - _wdt

Turns out you cannot use - on the namespace, but underscore _ instead. After renaming to my_api it started collecting data and working normally. Would be good to perhaps document this as well as what metrics are being collected.

denisvmedia commented 3 years ago

Hm... Not sure this is the case, will check it, and if it's true, I will add some validation to this parameter.

Anyway, jfyi:

namespace Artprima\PrometheusMetricsBundle\Metrics;

/**
 * Class AppMetrics is an implementation of basic metrics collector that is turned on by default.
 *
 * Collected metrics:
 * - requests (per method and route)
 * - responses (per method, route and response type)
 * - request duration histogram (per method and route)
 */
class AppMetrics implements MetricsGeneratorInterface {  /* implementation */ }

This is the default metrics class that is registered automatically (the interface name has a confusing name due to historical reasons; I'm thinking to rename it).

luispabon commented 3 years ago

This happens when using hyphen:

php-fpm_1      | [2021-01-06T12:32:46.352799+00:00] app.ERROR: Invalid metric name: 'my-api_instance_name' {"from":"request_collector","class":"Artprima\\PrometheusMetricsBundle\\Metrics\\AppMetrics"} []
php-fpm_1      | [2021-01-06T12:32:46.360506+00:00] app.ERROR: Invalid metric name: 'my-api_http_2xx_responses_total' {"from":"response_collector","class":"Artprima\\PrometheusMetricsBundle\\Metrics\\AppMetrics"} []

Digging some more, the exception is actually thrown from here: https://github.com/PromPHP/prometheus_client_php/blob/master/src/Prometheus/Collector.php#L46

Looks like it's validating the metric name against '/^[a-zA-Z_:][a-zA-Z0-9_:]*$/

denisvmedia commented 3 years ago

Thank you for your investigation! I'll update the bundle in terms of validation and docs. Please don't close the issue for now.

luispabon commented 3 years ago

Of course :ok_hand:

denisvmedia commented 3 years ago

Fixed in #34.