itk-dev / metrics-bundle
为 Prometheus 提供指标
1.1.0
2024-02-15 09:50 UTC
Requires
- php: ^8.1|^8.2|^8.3
- promphp/prometheus_client_php: ^2.2
- symfony/config: ~6.4|~7.0
- symfony/dependency-injection: ~6.4|~7.0
- symfony/framework-bundle: ~6.4|~7.0
- symfony/http-foundation: ~6.4|~7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.2
- vimeo/psalm: ^4.7
README
此包是 Symfony 的包装器,使得暴露 Prometheus 指标变得稍微容易一些。
它支持导出 Opcache 和 APCu 指标,以及您应用程序的自定义指标。
配置
支持将指标信息存储在 3 个不同的存储适配器中。默认推荐使用 Redis,因为它在重启后持久化。所以如果 Prometheus 拉取器没有收集数据,您不会丢失任何数据。
默认配置
itkdev_metrics: # Prefix exported metrics (should be application name) namespace: ItkDevApp # Storage adapter to use adapter: type: redis # One of "apcu"; "memory"; "redis" # Connection options is only used by redis adapter options: host: 127.0.0.1 port: 6379 password: ~ # Export metrics for these extensions extensions: opcache: false apcu: false
路由
该包暴露了 /metrics
路由,如果该路径已被占用,可以通过在 config/routes
下创建路由文件来添加前缀。
itkdev_metrics: prefix: '/custom/path/prefix' resource: '@ItkDevMetricsBundle/Resources/config/routes.xml'
服务
该包包含一个公共服务 MetricsService
,可用于收集自定义指标。它支持 Prometheus 的标准指标(计数器、仪表、直方图)。请参阅函数文档了解它们之间的区别以及如何使用它们。
更多信息请参阅: https://prometheus.ac.cn/docs/concepts/metric_types/