3slab/vdm-prometheus-bundle

Provide a metric endpoint to be pulled by Prometheus

Installs: 859

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 4

Forks: 1

Open Issues: 2

Type:symfony-bundle

1.2.0 2024-03-29 18:26 UTC

This package is auto-updated.

Last update: 2024-10-29 19:44:47 UTC


README

Build Status

This bundle provides a metric endpoint to be pulled by Prometheus. It uses the prometheus client from PromPHP

It collects the following metrics :

  • Memory in byte per route
  • Number of call to the API per response code
  • Response size in bytes
  • Request execution time in seconds

Response example :

# HELP php_info Information about the PHP environment.
# TYPE php_info gauge
php_info{version="7.3.11-0ubuntu0.19.10.6"} 1
# HELP vdm_sf_app_call_total Number of call to the app
# TYPE vdm_sf_app_call_total counter
vdm_sf_app_call_total{app="app",route=""} 1
vdm_sf_app_call_total{app="app",route="error_route"} 1
vdm_sf_app_call_total{app="app",route="success_route"} 2
# HELP vdm_sf_app_memory_usage Memory in byte per route
# TYPE vdm_sf_app_memory_usage gauge
vdm_sf_app_memory_usage{app="app",route=""} 25165824
vdm_sf_app_memory_usage{app="app",route="error_route"} 25165824
vdm_sf_app_memory_usage{app="app",route="success_route"} 25165824
# HELP vdm_sf_app_response_code_total Number of call to the API per response code
# TYPE vdm_sf_app_response_code_total counter
vdm_sf_app_response_code_total{app="app",route="",http_code="404"} 1
vdm_sf_app_response_code_total{app="app",route="error_route",http_code="500"} 1
vdm_sf_app_response_code_total{app="app",route="success_route",http_code="200"} 2
# HELP vdm_sf_app_response_size Response size in bytes
# TYPE vdm_sf_app_response_size gauge
vdm_sf_app_response_size{app="app",route=""} 305784
vdm_sf_app_response_size{app="app",route="error_route"} 5
vdm_sf_app_response_size{app="app",route="success_route"} 7
# HELP vdm_sf_app_response_time Request execution time in seconds
# TYPE vdm_sf_app_response_time gauge
vdm_sf_app_response_time{app="app",route=""} 81.976890563965
vdm_sf_app_response_time{app="app",route="error_route"} 0.10800361633301
vdm_sf_app_response_time{app="app",route="success_route"} 0.09608268737793

Installation

composer require 3slab/vdm-prometheus-bundle

And load the routes in routing.yml :

vdm_prometheus:
  resource: "@VdmPrometheusBundle/Resources/config/routing.yml"
  prefix:   /

Configuration

Put your configuration in config/packages/vdm_prometheus.yaml file. This is the default :

vdm_prometheus:
  app: app
  namespace: vdm
  register_default_metrics: true
  secret: ~
  metrics_path: /metrics
  storage:
    type: default

Metrics storage

To persist metrics between requests, you have to store them in persistent storage.

The following storage are supported :

  • In Memory (the default)
vdm_prometheus:
  storage:
    type: memory
  • APCu
vdm_prometheus:
  storage:
    type: apcu

You need to have the php module ext-apc installed.

  • Redis
vdm_prometheus:
  storage:
    type: redis
    settings:
      host: '127.0.0.1'
      port: 6379
      timeout: 0.1
      read_timeout: 10
      persistent_connections: false
      password: ~

You need to have the php module ext-redis installed.

  • Custom
vdm_prometheus:
  storage:
    type: custom
    service: my_service_id

With custom storage, you need to provide a Symfony service which implements the PromPHP Storage Adapter Interface

Custom collectors

You can create your own collector if you want to track other information.

Grafana

This bundle provides a grafana dashboard setup to work with default configuration for settings vdm_prometheus.app and vdm_prometheus.namespace.