5 Star 14 Fork 12

go-course / go12

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
collector.go 815 Bytes
一键复制 编辑 原始数据 按行查看 历史
Mr.Yu 提交于 2023-12-16 17:29 . 补充prom 自定义监控
package impl
import "github.com/prometheus/client_golang/prometheus"
func NewEventCollect() *EventCollect {
return &EventCollect{
errCountDesc: prometheus.NewDesc(
"save_event_error_count",
"事件入库失败个数统计",
[]string{},
prometheus.Labels{"service": "maudit"},
),
}
}
// 收集事件指标的采集器
type EventCollect struct {
errCountDesc *prometheus.Desc
// 需要自己根据实践情况来维护这个变量
errCount int
}
func (c *EventCollect) Inc() {
c.errCount++
}
// 指标元数据注册
func (c *EventCollect) Describe(ch chan<- *prometheus.Desc) {
ch <- c.errCountDesc
}
// 指标的值的采集
func (c *EventCollect) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(c.errCountDesc, prometheus.GaugeValue, float64(c.errCount))
}
Go
1
https://gitee.com/go-course/go12.git
git@gitee.com:go-course/go12.git
go-course
go12
go12
f5108b3d9dc2

搜索帮助