1 使用脚本的方式
1.1 添加取值脚本
vim /opt/node_exporter/key/key_runner
#!/bin/bashecho ClickHouse_Ping `ps -ef|grep clickhouse-server|grep -v grep|wc -l`
1.2 设置定时任务
* * * * * bash /opt/node_exporter/key/key_runner > /opt/node_exporter/key/key.prom
1.3 启动 node_exporter
/opt/node_exporter/node_exporter --web.listen-address=:9101 --collector.textfile.directory=/opt/node_exporter/key/ &
1.4 验证
curl 127.0.0.1:9101/metrics|grep ClickHouse_Ping
......# TYPE ClickHouse_Ping untypedClickHouse_Ping 1
1.5 后续监控项
2 自己编写一个 Exporter
package mainimport ("fmt""net/http""time")func GetTimeStamp() int64 {return time.Now().Unix()}func HelloHandler(w http.ResponseWriter, r *http.Request) {fmt.Fprintf(w, "martin_exporter_get_timestamp{user=\"admin\"} %d", GetTimeStamp())}func main() {http.HandleFunc("/metrics", HelloHandler)http.ListenAndServe(":8001", nil)}
martin_exporter_get_timestamp{user="admin"} 1639031311
3 结合 pushgateway
3.1 安装 pushgateway
wget https://github.com/prometheus/pushgateway/releases/download/v1.4.2/pushgateway-1.4.2.linux-amd64.tar.gztar zxvf pushgateway-1.4.2.linux-amd64.tar.gzcd pushgateway-1.4.2.linux-amd64/cp pushgateway /usr/local/bin/
nohup pushgateway --web.listen-address="0.0.0.0:9091" &
3.2 发送和查看自定义指标
echo 'martin_test_count 1'|curl --data-binary @- http://192.168.150.123:9091/metrics/job/martintest
......martin_test_count{instance="",job="martintest"} 1......
文章转载自DevOps实战,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




