Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

告警tags问题 #940

Open
SREbo opened this issue Sep 9, 2021 · 2 comments
Open

告警tags问题 #940

SREbo opened this issue Sep 9, 2021 · 2 comments

Comments

@SREbo
Copy link

SREbo commented Sep 9, 2021

告警模版里添加了
fstype=ext4,mount=/data
fstype=ext4,mount=/
两个tags ,我们不想收到fstype=tmpfs,mount=/data/docker/containers/82036ff6674487c8daa820b3ecf43907df2e479cba7e8a564a06963c4cfec47a/mounts/shm类似这样的tags的磁盘告警。需要怎么配置呢

@bbaobelief
Copy link

agent上报的时候就屏蔽掉

@wangwenjie2500
Copy link

我们的解决办法是在agent里面屏蔽掉指定标签的数据
agent/cron/g/cfg.go
type GlobalConfig struct {
Debug bool json:"debug"
Hostname string json:"hostname"
IP string json:"ip"
Plugin *PluginConfig json:"plugin"
Heartbeat *HeartbeatConfig json:"heartbeat"
Transfer *TransferConfig json:"transfer"
Http *HttpConfig json:"http"
Collector *CollectorConfig json:"collector"
DefaultTags map[string]string json:"default_tags"
IgnoreMetrics map[string]bool json:"ignore"
IgnoreTags map[string]bool json:"ignore_tags"
}

agent/cfg.conf
"ignore_tags" : {
"fstype=overlay": true,
"fstype=tmpfs" : true
}

agent/cron/collector.go

func collect(sec int64, fns []func() []*model.MetricValue) {
t := time.NewTicker(time.Second * time.Duration(sec))
defer t.Stop()
for {
<-t.C

	hostname, err := g.Hostname()
	if err != nil {
		continue
	}

	mvs := []*model.MetricValue{}
	ignoreMetrics := g.Config().IgnoreMetrics
	ignoreTags := g.Config().IgnoreTags
	for _, fn := range fns {
		items := fn()
		if items == nil {
			continue
		}

		if len(items) == 0 {
			continue
		}

		for _, mv := range items {
			if b, ok := ignoreMetrics[mv.Metric]; ok && b { //不允许上报metric
				continue
			} else {
				count := 0
				for tags,status := range ignoreTags { //检查上报的tag中是否包含要拒绝的tag
					if find := strings.Contains(mv.Tags,tags);find && status {
						count += 1
						break
					}
				}
				if count == 0 { //当metric/tag都不在拒绝的列表里面才能上报
					mvs = append(mvs, mv)
				}
			}
		}
	}

	now := time.Now().Unix()
	for j := 0; j < len(mvs); j++ {
		mvs[j].Step = sec
		mvs[j].Endpoint = hostname
		mvs[j].Timestamp = now
	}

	g.SendToTransfer(mvs)

}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants