yii2-prometheus
Prometheus Extension for Yii 2
This extension provides a Prometheus exporter component for Yii framework 2.0 applications.
This extension uses the textfile collector of Node Exporter for Prometheus.
Installation
The preferred way to install this extension is through composer.
composer require --prefer-dist machour/yii2-prometheus
Configuration
In order to exploit the metrics files generated by this extension, you must run the node exporter using the --collector.textfile.directory
flag, and point it to a valid directory.
If using systemd to manage your scrappers, your node_exporter.service
file may look something like this:
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
Once the extension is installed, simply modify your application configuration as follows:
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',
],
// ...
],
...
];