node_exporter 自定義監控

mixboot發表於2020-12-26
# cd node_exporter-1.0.1.linux-amd64/
# mkdir key
# touch height.sh
# cat height.sh
#!/bin/bash

height=`curl -X POST \
	 -H "Content-Type: application/json" \
	 -H "Authorization: Bearer $(cat /seal/lotus/token)" \
	 --data '{ "jsonrpc": "2.0", "method": "Filecoin.ChainHead", "params": [], "id": 1 }' \
	 'http://127.0.0.1:1234/rpc/v0' \
	 | jq .result.Height`

date +'%Y-%m-%d %H:%M:%S'
echo "height $height"
2020-12-25 21:41:01
height 353241
# crontab -l
* * * * * /bin/bash /root/node_exporter-1.0.1.linux-amd64/key/height.sh > /root/node_exporter-1.0.1.linux-amd64/key/key.prom

--collector.textfile.directory

vim /lib/systemd/system/node_exporter.service
# cat /lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter service

[Service]
User=root
ExecStart=/root/node_exporter-1.0.1.linux-amd64/node_exporter \
	 --collector.textfile.directory=/root/node_exporter-1.0.1.linux-amd64/key

TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl restart node_exporter.service
  • 獲取到 height
# curl http://localhost:9100/metrics | grep height
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0# HELP height Metric read from /root/node_exporter-1.0.1.linux-amd64/key/key.prom
# TYPE height untyped
height 355308
100 77348    0 77348    0     0  2288k      0 --:--:-- --:--:-- --:--:-- 2288k

參考:

  1. node_exporter新增自定義監控項
  2. Node-Exporter採集自定義Metrics
  3. github node_exporter

相關文章