artprima / prometheus-metrics-bundle

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

Missing default metrics #76

Closed b2p-fred closed 2 years ago

b2p-fred commented 2 years ago

Just after a fresh install, I configured as:

artprima_prometheus_metrics:
  namespace: mymetrics

  storage:
    type: in_memory

  ignored_routes:
    - prometheus_bundle_prometheus
    - _wdt

  # used to disable default application metrics
  disable_default_metrics: false

  # used to disable default metrics from promphp/prometheus_client_php
  disable_default_promphp_metrics: false

  # used to enable console metrics
  enable_console_metrics: true

and I only get:

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

when I request on http://localhost:8000/metrics/prometheus

I expected to have, at minimum, the metrics listed in your example in the README.md:

# TYPE php_info gauge
php_info{version="7.3.25-1+ubuntu18.04.1+deb.sury.org+1"} 1
# HELP symfony_http_2xx_responses_total total 2xx response count
# TYPE symfony_http_2xx_responses_total counter
symfony_http_2xx_responses_total{action="GET-app_dummy_homepage"} 1
symfony_http_2xx_responses_total{action="all"} 1
# HELP symfony_http_requests_total total request count
# TYPE symfony_http_requests_total counter
symfony_http_requests_total{action="GET-app_dummy_homepage"} 1
symfony_http_requests_total{action="all"} 1
# HELP symfony_instance_name app instance name
# TYPE symfony_instance_name gauge
symfony_instance_name{instance="dev"} 1

Any idea of a misconfiguration ?

denisvmedia commented 2 years ago

To generate the default metrics, you first need to visit any non-ignored route

b2p-fred commented 2 years ago

I still did opened several non-ignored routes. I also ran all my automatic tests.

My application has only one Twig templated page and a JSON API I implemented with api-platform. Whatever the requests I am doing the metrics page is always the same... only a php_info :(

denisvmedia commented 2 years ago

Note, that you use in_memory storage type. It's only to be used in tests. You should switch to redis or to apcu.

b2p-fred commented 2 years ago

I was aware of this. Do you think it may cause my lack of metrics ? I will give a try with redis...

b2p-fred commented 2 years ago

I changed my configuration to :

artprima_prometheus_metrics:
  namespace: mymetrics

  # metrics backend
  storage:
#    # DSN of the storage. All parsed values will override explicitly set parameters. Ex: redis://127.0.0.1?timeout=0.1
#    url: ~

    # Known values: in_memory, apcu, apcng, redis
    type: redis

    # Available parameters used by redis
    host: redis
    port: 6379
    timeout: 0.1
    read_timeout: 10
    persistent_connections: false
    password: ~
    database: 1 # Int value used by redis adapter
    prefix: epr  # String value used by redis and apcu

    # A variable parameter to define additional options as key / value.
    options:
      foo: bar

  ignored_routes:
    - prometheus_bundle_prometheus
    - _wdt

  # used to disable default application metrics
  disable_default_metrics: false

  # used to disable default metrics from promphp/prometheus_client_php
  disable_default_promphp_metrics: false

  # used to enable console metrics
  enable_console_metrics: true

and now I have a bunch of metrics!

When I switch back to the in_memory storage there is only php_info ...

denisvmedia commented 2 years ago

As I said in_memory is not meant to be used in the real applications (unless you run php as a daemon, which is rarely the case). It will be flushed out with every http-request.

Johnmeurt commented 2 years ago

The memory storage is not shared. The controller could not have access to the metrics set by a different process.

b2p-fred commented 2 years ago

IMHO, perhaps you should not define the in_memory as the default configuration and you should raise an alert about this in the README ;)

Thanks for your replies

b2p-fred commented 2 years ago

Some more information to help understanding missing metrics ...

Almost all the tests I ran are based on Phpunit or behat and they use a "simulated" browser client ... and as soon as I use a "real" client all the counters for all the routes are updated !