3slab/vdm-prometheus-bundle

提供Prometheus拉取的度量端点

安装: 851

依赖项: 0

建议者: 0

安全: 0

星星: 2

关注者: 4

分支: 1

开放问题: 2

类型:symfony-bundle

1.2.0 2024-03-29 18:26 UTC

This package is auto-updated.

Last update: 2024-09-29 19:29:13 UTC


README

Build Status

此包提供由Prometheus拉取的度量端点。它使用了PromPHP的Prometheus客户端

它收集以下度量

  • 每路由的字节内存
  • 每个响应代码的API调用次数
  • 响应大小(字节)
  • 请求执行时间(秒)

响应示例

# 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

安装

composer require 3slab/vdm-prometheus-bundle

并在routing.yml中加载路由

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

配置

将配置放入config/packages/vdm_prometheus.yaml文件中。这是默认配置

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

度量存储

要持久化度量以在请求之间保持,您必须将它们存储在持久存储中。

以下存储支持

  • 内存中 (默认)
vdm_prometheus:
  storage:
    type: memory
  • APCu
vdm_prometheus:
  storage:
    type: apcu

您需要安装php模块ext-apc

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

您需要安装php模块ext-redis

  • 自定义
vdm_prometheus:
  storage:
    type: custom
    service: my_service_id

使用自定义存储,您需要提供一个实现PromPHP存储适配器接口的Symfony服务

自定义收集器

如果您想跟踪其他信息,您可以创建自己的收集器

Grafana

此包提供了一个Grafana仪表板配置,用于与默认配置设置vdm_prometheus.appvdm_prometheus.namespace一起工作。