diff --git a/ChangeLog.md b/ChangeLog.md index bb66daa..4054b41 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,16 @@ +# Changelog # +## 4.0.6.3 ## +#### bug修复 #### +1. 现在当 tag 为空时,debug 应该会正确打印对应的日志了 +2. 修复了一个当自定义 oid 超过 2 项,且 oid 不正确无法采集到信息时,swcollector 会异常崩溃的 bug +3. 修复了一个当 speedlimit 使用指定值(而非自动采用接口速率 ifSpeed)作为限制时,接口的 speedPercent 无法正确采集的 bug +#### 改进 #### +1. 配置热重载模式调整,现在 reload 后会在下一个采集周期时重载配置。并清空 AliveIp,因此配置中移除的 IP 可以正确生效了 +2. swcollector 自带的 http 页,现在应该能更快速的显示了 +3. swcollector 自带的 http 页,现在支持更多交换机的 sysmodle 了 +4. cpu 和 mem 现在对于老版本的 H3C (H3C Comware Platform Software Comware software, Version 3.10),应该也能正确采集到了 + + # Changelog # ## 4.0.6.2 ## #### 新功能 #### diff --git a/README.md b/README.md index f11ce0d..f23cdaa 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,12 @@ CPU和内存的OID私有,根据设备厂家和OS版本可能不同。目前测 * Huawei VRP(Version 5.130) * Huawei VRP(Version 5.70) * Juniper JUNOS(Version 10) +* H3C(Version 3.1) * H3C(Version 5) * H3C(Version 5.20) * H3C(Version 7) * DELL +* Linux #### 二进制安装 从[这里](https://github.com/gaochao1/swcollector/releases) 下载编译好的最新二进制版本即可。注意:这些二进制只能跑在64位Linux上 diff --git a/funcs/custmetric.go b/funcs/custmetric.go index 0b28845..8022c50 100644 --- a/funcs/custmetric.go +++ b/funcs/custmetric.go @@ -52,10 +52,10 @@ func CustMetrics() (L []*model.MetricValue) { chs := make([]chan CustM, 0) for _, ip := range AliveIp { if ip != "" { - chss := make(chan CustM) for _, metric := range g.CustConfig().Metrics { CustmIps := AllCustmIp(metric.IpRange) if InArray(ip, CustmIps) { + chss := make(chan CustM) go custMetrics(ip, metric, chss) chs = append(chs, chss) } @@ -87,7 +87,6 @@ func custMetrics(ip string, metric *g.MetricConfig, ch chan CustM) { var custm CustM var custmmetric CustmMetric var custmmetrics []CustmMetric - value, err := GetCustMetric(ip, g.Config().Switch.Community, metric.Oid, g.Config().Switch.SnmpTimeout, g.Config().Switch.SnmpRetry) if err != nil { log.Println(ip, metric.Oid, err) diff --git a/funcs/swifstat.go b/funcs/swifstat.go index e38bed3..3bf6d13 100644 --- a/funcs/swifstat.go +++ b/funcs/swifstat.go @@ -126,6 +126,18 @@ func SwIfMetrics() (L []*model.MetricValue) { } func swIfMetrics() (L []*model.MetricValue) { + if g.ReloadType() { + g.ParseConfig(g.ConfigFile) + if g.Config().SwitchHosts.Enabled { + hostcfg := g.Config().SwitchHosts.Hosts + g.ParseHostConfig(hostcfg) + } + if g.Config().CustomMetrics.Enabled { + custMetrics := g.Config().CustomMetrics.Template + g.ParseCustConfig(custMetrics) + } + AliveIp = nil + } initVariable() ts := time.Now().Unix() allIp := AllSwitchIp() @@ -355,7 +367,7 @@ func swIfMetrics() (L []*model.MetricValue) { IfHCOutOctets := 8 * (float64(ifStat.IfHCOutOctets) - float64(lastifStat.IfHCOutOctets)) / float64(interval) if limitCheck(IfHCInOctets, speedlimit) { L = append(L, GaugeValueIp(ts, ip, "switch.if.In", IfHCInOctets, ifNameTag, ifIndexTag)) - if speedlimit > 0 { + if ifStat.IfSpeed > 0 { InSpeedPercent := 100 * IfHCInOctets / float64(ifStat.IfSpeed) L = append(L, GaugeValueIp(ts, ip, "switch.if.InSpeedPercent", InSpeedPercent, ifNameTag, ifIndexTag)) } @@ -366,7 +378,7 @@ func swIfMetrics() (L []*model.MetricValue) { } if limitCheck(IfHCOutOctets, speedlimit) { L = append(L, GaugeValueIp(ts, ip, "switch.if.Out", IfHCOutOctets, ifNameTag, ifIndexTag)) - if speedlimit > 0 { + if ifStat.IfSpeed > 0 { OutSpeedPercent := 100 * IfHCOutOctets / float64(ifStat.IfSpeed) L = append(L, GaugeValueIp(ts, ip, "switch.if.OutSpeedPercent", OutSpeedPercent, ifNameTag, ifIndexTag)) } diff --git a/g/cfg.go b/g/cfg.go index 671e247..f113e14 100644 --- a/g/cfg.go +++ b/g/cfg.go @@ -84,9 +84,24 @@ type GlobalConfig struct { var ( ConfigFile string config *GlobalConfig + reloadType bool lock = new(sync.RWMutex) + rlock = new(sync.RWMutex) ) +func SetReloadType(t bool) { + rlock.RLock() + defer rlock.RUnlock() + reloadType = t + return +} + +func ReloadType() bool { + rlock.RLock() + defer rlock.RUnlock() + return reloadType +} + func Config() *GlobalConfig { lock.RLock() defer lock.RUnlock() @@ -119,7 +134,7 @@ func ParseConfig(cfg string) { defer lock.Unlock() config = &c - + SetReloadType(false) log.Println("read config file:", cfg, "successfully") } diff --git a/g/const.go b/g/const.go index 3836932..4f5fd98 100644 --- a/g/const.go +++ b/g/const.go @@ -20,7 +20,8 @@ import ( // 4.0.5 add custom metric,custom host // 4.0.6.1 fix channal closed bug // 4.0.6.2 fix Vendor bug;add remote config api +// 4.0.6.3 fix bugs const ( - VERSION = "4.0.6.2" + VERSION = "4.0.6.3" COLLECT_INTERVAL = time.Second ) diff --git a/g/var.go b/g/var.go index f976496..f50af56 100644 --- a/g/var.go +++ b/g/var.go @@ -71,6 +71,10 @@ func SendToTransfer(metrics []*model.MetricValue) { for _, metric := range metrics { metric_tags := strings.Split(metric.Tags, ",") if in_array(metric.Endpoint, debug_endpoints) && in_array(metric.Metric, debug_metrics) { + if debug_tags == "" { + log.Printf("=> %v\n", len(metrics), metric) + continue + } if array_include(debug_Tags, metric_tags) { log.Printf("=> %v\n", len(metrics), metric) } diff --git a/http/admin.go b/http/admin.go index 157ce75..6ce3a88 100644 --- a/http/admin.go +++ b/http/admin.go @@ -1,6 +1,7 @@ package http import ( + "log" "net/http" "os" "time" @@ -31,16 +32,9 @@ func configAdminRoutes() { }) http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) { if g.IsTrustable(r.RemoteAddr) { - g.ParseConfig(g.ConfigFile) - if g.Config().SwitchHosts.Enabled { - hostcfg := g.Config().SwitchHosts.Hosts - g.ParseHostConfig(hostcfg) - } - if g.Config().CustomMetrics.Enabled { - custMetrics := g.Config().CustomMetrics.Template - g.ParseCustConfig(custMetrics) - } - RenderDataJson(w, g.Config()) + g.SetReloadType(true) + log.Println("config will be reload in next interval") + RenderDataJson(w, "reload type on") } else { w.Write([]byte("no privilege")) } diff --git a/main.go b/main.go index 50e41b2..f14eded 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,6 @@ func main() { fmt.Println(g.VERSION) os.Exit(0) } - g.ParseConfig(*cfg) if g.Config().SwitchHosts.Enabled { hostcfg := g.Config().SwitchHosts.Hosts @@ -41,6 +40,7 @@ func main() { funcs.CheckCollector() os.Exit(0) } + funcs.NewLastifMap() funcs.BuildMappers()