node_exporter 自定义监控

# 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
上一篇:ubuntu 下 切换多个jdk版本


下一篇:在windows系统下打包linux平台运行的go程序