tweedegolf / prometheus-bundle
此包已被弃用,不再维护。未建议替代包。
Prometheus客户端的Symfony扩展包
v0.4.0
2020-12-09 13:54 UTC
Requires
- php: >=7.1.3
- symfony/config: ~2.7|~3.0|~4.0|~5.0
- symfony/dependency-injection: ~2.7|~3.0|~4.0|~5.0
- symfony/framework-bundle: ~2.7|~3.0|~4.0|~5.0
- symfony/http-kernel: ~2.7|~3.0|~4.0|~5.0
- tweedegolf/prometheus-client: ^0.3
This package is not auto-updated.
Last update: 2023-06-29 10:28:37 UTC
README
A Symfony bundle for the tweede golf prometheus client. For more information on Prometheus you can check their website.
安装和配置
使用 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 make_memory_adapter: true register_defaults: true 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]