1 使用脚本的方式
1.1 添加取值脚本
vim /opt/node_exporter/key/key_runner
复制
#!/bin/bash
echo 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 untyped
ClickHouse_Ping 1
复制
1.5 后续监控项
2 自己编写一个 Exporter
package main
import (
"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.gz
tar zxvf pushgateway-1.4.2.linux-amd64.tar.gz
cd 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进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年4月中国数据库流行度排行榜:OB高分复登顶,崖山稳驭撼十强
墨天轮编辑部
2465次阅读
2025-04-09 15:33:27
数据库国产化替代深化:DBA的机遇与挑战
代晓磊
1141次阅读
2025-04-27 16:53:22
2025年3月国产数据库中标情况一览:TDSQL大单622万、GaussDB大单581万……
通讯员
820次阅读
2025-04-10 15:35:48
2025年4月国产数据库中标情况一览:4个千万元级项目,GaussDB与OceanBase大放异彩!
通讯员
648次阅读
2025-04-30 15:24:06
数据库,没有关税却有壁垒
多明戈教你玩狼人杀
567次阅读
2025-04-11 09:38:42
天津市政府数据库框采结果公布,7家数据库产品入选!
通讯员
549次阅读
2025-04-10 12:32:35
国产数据库需要扩大场景覆盖面才能在竞争中更有优势
白鳝的洞穴
530次阅读
2025-04-14 09:40:20
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
456次阅读
2025-04-17 17:02:24
一页概览:Oracle GoldenGate
甲骨文云技术
452次阅读
2025-04-30 12:17:56
GoldenDB数据库v7.2焕新发布,助力全行业数据库平滑替代
GoldenDB分布式数据库
439次阅读
2025-04-30 12:17:50