Skip to content

Commit

Permalink
VERSION 4.1.3
Browse files Browse the repository at this point in the history
1. 允许去除 index tag,以在 n9e 上获得更好的体验
  • Loading branch information
freedomkk-qfeng committed Jul 2, 2020
1 parent 9c84992 commit 501853c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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认证字符串
Expand Down
1 change: 1 addition & 0 deletions cfg.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"10.10.88.168"
],
"gosnmp":true,
"index_tag":false,
"pingTimeout":300,
"pingRetry":4,
"community":"123456",
Expand Down
21 changes: 16 additions & 5 deletions funcs/common.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion funcs/swifstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 4 additions & 3 deletions g/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion g/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 501853c

Please sign in to comment.