Skip to content

Commit

Permalink
4.0.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
freedomkk-qfeng committed Sep 22, 2017
1 parent b68c7ed commit 2761f50
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 17 deletions.
13 changes: 13 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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 ##
#### 新功能 ####
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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上
Expand Down
3 changes: 1 addition & 2 deletions funcs/custmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions funcs/swifstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down
17 changes: 16 additions & 1 deletion g/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -119,7 +134,7 @@ func ParseConfig(cfg string) {
defer lock.Unlock()

config = &c

SetReloadType(false)
log.Println("read config file:", cfg, "successfully")

}
3 changes: 2 additions & 1 deletion g/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 4 additions & 0 deletions g/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("=> <Total=%d> %v\n", len(metrics), metric)
continue
}
if array_include(debug_Tags, metric_tags) {
log.Printf("=> <Total=%d> %v\n", len(metrics), metric)
}
Expand Down
14 changes: 4 additions & 10 deletions http/admin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http

import (
"log"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -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"))
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +40,7 @@ func main() {
funcs.CheckCollector()
os.Exit(0)
}

funcs.NewLastifMap()
funcs.BuildMappers()

Expand Down

0 comments on commit 2761f50

Please sign in to comment.