machour / yii2-prometheus
Yii 2 的 Prometheus 导出器
2.0.1
2021-10-23 09:04 UTC
Requires
- php: >=5.4
- yiisoft/yii2: ~2.0.13
Requires (Dev)
- cweagans/composer-patches: ^1.7
- phpunit/phpunit: ^4.8.36
README
Yii 2 的 Prometheus 扩展
此扩展为 Prometheus 提供了用于 Yii 框架 2.0 应用程序的导出器组件。
此扩展使用 Prometheus 的 Node Exporter 文本文件收集器。
安装
安装此扩展的首选方式是通过 Composer。
composer require --prefer-dist machour/yii2-prometheus
配置
为了利用此扩展生成的指标文件,您必须使用 --collector.textfile.directory
标志运行 node exporter,并将其指向一个有效的目录。
如果您使用 systemd 来管理您的爬虫,您的 node_exporter.service
文件可能看起来像这样
node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/usr/local/bin/node_exporter --collector.textfile.directory /var/lib/node_exporter/textfile_collector --web.listen-address="127.0.0.1:9100"
[Install]
WantedBy=default.target
扩展安装后,只需按以下方式修改您的应用程序配置
return [ 'components' => [ 'prometheusExporter' => [ 'class' => 'machour\yii2\prometheus\components\Exporter', // Point this to your collector directory. Defaults to '/var/lib/node_exporter/textfile_collector/' // 'collectorDir' => '/var/lib/node_exporter/textfile_collector/', // The default prom file to create if not specified in exportMetric() // 'defaultFile' => 'yii2-prometheus-exporter.prom', ], // ... ], ... ];