替代pushgateway 的思路

pushgateway 替代

为啥要替代?
因为pushgateway不好用。

思路

定义一个webServer

  • port1:用于提交监控数据
  • port2:用于prometheus配置target

缺点说明:这个不是及时推送到prometheus,依然是被动提供数据

port1

用来上传各个脚本采集的数据,临时传到webServer上。
数据结构,按照prometheus的数据结构来定义,

metrics_name{tag_name="tag_value"} filed_value

#当然也可以像这样加上说明:
#HELP metrics_name some word to explain
#TYPE metrics_name counter\Gauge\...
metrics_name{tag_name="tag_value"} field_value

port2

汇总port1搜集到的数据汇总起来,用于prometheus配置target。

至于数据怎么存、怎么汇总就看具体需求了。举个小栗子

func Start() {
	//for prometheus target
	http.HandleFunc("/metrics", metrics)
	//upload metrics
	http.HandleFunc("/upload", upload())
	fs := http.FileServer(http.Dir(uploadPath))
	http.Handle("/files/", http.StripPrefix("/files", fs))
	//设置监听的端口
	err := http.ListenAndServe(":8045", nil)
	//异常
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}

func metrics(w http.ResponseWriter, r *http.Request) {
	fmt.Println("metrics.txt")
	w.Header().Set("Access-Control-Allow-Origin", "*")
	content, _ := ioutil.ReadFile("./metrics.txt")
	w.Write(content)
}

func upload() http.HandlerFunc {
	//这里数据汇总,存到metrics.txt
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值