3slab / tweedegolf-prometheus-bundle
此包已被放弃,不再维护。未建议替代包。
Prometheus 客户端 Symphony 扩展包
v0.2.3
2018-07-30 08:40 UTC
Requires
- php: >=7.1.3
- symfony/config: ~4.0
- symfony/dependency-injection: ~4.0
- symfony/http-kernel: ~4.0
- tweedegolf/prometheus-client: ^0.2
This package is not auto-updated.
Last update: 2020-12-26 09:19:12 UTC
README
为 tweede golf prometheus 客户端 提供的 Symfony 扩展包。有关 Prometheus 的更多信息,您可以 访问他们的网站。
安装和配置
使用 Composer,通过 require 命令将扩展包添加到您的依赖中
composer require tweedegolf/prometheus-bundle
将扩展包添加到您的 AppKernel
在您的 app/AppKernel.php
中添加扩展包
public function registerBundles() { return array( // ... new TweedeGolf\PrometheusBundle\TweedeGolfPrometheusBundle(), // ... ); }
配置存储、收集器和路由
为了允许 Prometheus 从您的应用程序中抓取指标,确保您为 Prometheus 指标控制器创建一个可用的路由
tweede_golf_prometheus: resource: "@TweedeGolfPrometheusBundle/Resources/config/routing.yml" prefix: /
您还可以实现自己的控制器,查看 TweedeGolf\PrometheusBundle\Controller\MetricsController::metricsAction
的源代码。您可以使用配置来配置 Prometheus 客户端的一些方面,以下显示默认值
tweede_golf_prometheus: storage_adapter_service: TweedeGolf\PrometheusClient\Storage\ApcuAdapter metrics_path: /metrics collectors: ~
要调整,在您的 config.yml
中创建一个 tweede_golf_prometheus
部分。您可以指定任意数量的收集器。以下是一个定义了四个不同收集器的示例
tweede_golf_prometheus: collectors: requests: counter: labels: [url] help: Number of requests throughput: gauge: labels: [url] help: Throughput per url initializer: 10.0 response_timing: histogram: labels: [url] help: Response timings buckets: [0.1, 0.2, 0.3, 0.5, 0.7, 1, 2, 5, 10, 30, 60] shorthand_example: counter: ~
修改(增加/观察/设置)指标
要修改指标,通过 CollectorRegistry
服务检索它并调用一种类型特定的指标修改方法。
use TweedeGolf\PrometheusClient\CollectorRegistry; public function exampleAction() { $metric = $this->get(CollectorRegistry::class)->getCounter('requests'); $metric->inc(); }
注册收集器服务
您还可以将服务注册为收集器。为此,在您的服务中添加一个 tweede_golf_prometheus.collector
标签,并确保服务实现了 CollectorInterface
。您还可以使用注册服务工厂方法
services: example.collector.test: class: TweedeGolf\PrometheusClient\Collector\Counter factory: TweedeGolf\PrometheusClient\CollectorRegistry:createCounter arguments: [test] tags: [tweede_golf_prometheus.collector]