Open SREbo opened 3 years ago
agent上报的时候就屏蔽掉
我们的解决办法是在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)
}
}
告警模版里添加了 fstype=ext4,mount=/data fstype=ext4,mount=/ 两个tags ,我们不想收到fstype=tmpfs,mount=/data/docker/containers/82036ff6674487c8daa820b3ecf43907df2e479cba7e8a564a06963c4cfec47a/mounts/shm类似这样的tags的磁盘告警。需要怎么配置呢