diff --git a/README.md b/README.md index 287340b..05b182a 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ swcollector需要部署到有交换机SNMP访问权限的服务器上。 "172.16.114.233" ], "gosnmp":true, #是否使用 gosnmp 采集, false 则使用 snmpwalk + "index_tag":false, #去掉 index tag 以在 n9e 上获得更好体验 "pingTimeout":300, #Ping超时时间,单位毫秒 "pingRetry":4, #Ping探测重试次数 "community":"public", #SNMP认证字符串 diff --git a/cfg.example.json b/cfg.example.json index 154890f..e0a88cf 100644 --- a/cfg.example.json +++ b/cfg.example.json @@ -11,6 +11,7 @@ "10.10.88.168" ], "gosnmp":true, + "index_tag":false, "pingTimeout":300, "pingRetry":4, "community":"123456", diff --git a/funcs/common.go b/funcs/common.go index 89c4d45..2bc58e1 100644 --- a/funcs/common.go +++ b/funcs/common.go @@ -1,9 +1,10 @@ package funcs import ( + "strings" + "github.com/gaochao1/swcollector/g" "github.com/open-falcon/common/model" - "strings" ) func NewMetricValue(metric string, val interface{}, dataType string, tags ...string) *model.MetricValue { @@ -14,9 +15,14 @@ func NewMetricValue(metric string, val interface{}, dataType string, tags ...str } size := len(tags) - + validTags := []string{} + for _, t := range tags { + if t != "" { + validTags = append(validTags, t) + } + } if size > 0 { - mv.Tags = strings.Join(tags, ",") + mv.Tags = strings.Join(validTags, ",") } return &mv @@ -43,9 +49,14 @@ func NewMetricValueIp(TS int64, ip, metric string, val interface{}, dataType str } size := len(tags) - + validTags := []string{} + for _, t := range tags { + if t != "" { + validTags = append(validTags, t) + } + } if size > 0 { - mv.Tags = strings.Join(tags, ",") + mv.Tags = strings.Join(validTags, ",") } return &mv diff --git a/funcs/swifstat.go b/funcs/swifstat.go index 3bf6d13..b6b4960 100644 --- a/funcs/swifstat.go +++ b/funcs/swifstat.go @@ -175,7 +175,10 @@ func swIfMetrics() (L []*model.MetricValue) { for _, ifStat := range *chIfStat.IfStatsList { ifNameTag := "ifName=" + ifStat.IfName - ifIndexTag := "ifIndex=" + strconv.Itoa(ifStat.IfIndex) + ifIndexTag := "" + if g.Config().Switch.IndexTag { + ifIndexTag = "ifIndex=" + strconv.Itoa(ifStat.IfIndex) + } ip := chIfStat.Ip if ignoreOperStatus == false { L = append(L, GaugeValueIp(ifStat.TS, ip, "switch.if.OperStatus", ifStat.IfOperStatus, ifNameTag, ifIndexTag)) diff --git a/g/cfg.go b/g/cfg.go index 383a746..464c0aa 100644 --- a/g/cfg.go +++ b/g/cfg.go @@ -15,9 +15,10 @@ type DebugmetricConfig struct { } type SwitchConfig struct { - Enabled bool `json:"enabled"` - IpRange []string `json:"ipRange"` - Gosnmp bool `json:"gosnmp"` + Enabled bool `json:"enabled"` + IpRange []string `json:"ipRange"` + IndexTag bool `json:"index_tag"` + Gosnmp bool `json:"gosnmp"` PingTimeout int `json:"pingTimeout"` PingRetry int `json:"pingRetry"` diff --git a/g/const.go b/g/const.go index 7317c66..75854c1 100644 --- a/g/const.go +++ b/g/const.go @@ -24,6 +24,6 @@ import ( // 4.1.0 support n9e transfer mode // 4.1.1 n9e mode support debug const ( - VERSION = "4.1.2" + VERSION = "4.1.3" COLLECT_INTERVAL = time.Second )