Понадобилось снимать свои метрики в Prometheus и Node Exporter. Больше информации тут: https://www.robustperception.io/using-the-textfile-collector-from-a-shell-script
1) Создаем service в /etc/systemd/system/node_exporter.service и запускаем service с ключом --collector.textfile.directory=/var/lib/node_exporter/textfile_collector
[Unit]
Description=node_exporter
[Service]
User=root
Group=root
Type=Simple
ExecStart=/etc/node_exporter/node_exporter --collector.textfile.directory=/var/lib/node_exporter/textfile_collector
WorkingDirectory=/etc/node_exporter
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
2) Сам баш скрипт.
1) Создаем service в /etc/systemd/system/node_exporter.service и запускаем service с ключом --collector.textfile.directory=/var/lib/node_exporter/textfile_collector
[Unit]
Description=node_exporter
[Service]
User=root
Group=root
Type=Simple
ExecStart=/etc/node_exporter/node_exporter --collector.textfile.directory=/var/lib/node_exporter/textfile_collector
WorkingDirectory=/etc/node_exporter
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
2) Сам баш скрипт.
#!/bin/bash | |
# Adjust as needed. | |
#https://www.robustperception.io/using-the-textfile-collector-from-a-shell-script | |
TEXTFILE_COLLECTOR_DIR=/var/lib/node_exporter/textfile_collector/ | |
# Note the start time of the script. | |
# Your code goes here. | |
sleep 10 | |
# Write out metrics to a temporary file. | |
END="$(cat /var/log/cron | wc -l)" | |
cat << EOF > "$TEXTFILE_COLLECTOR_DIR/test.prom.$$" | |
test $END | |
EOF | |
# Rename the temporary file atomically. | |
# This avoids the node exporter seeing half a file. | |
mv "$TEXTFILE_COLLECTOR_DIR/test.prom.$$" \ | |
"$TEXTFILE_COLLECTOR_DIR/test.prom" |
Комментариев нет:
Отправить комментарий