Skip to content

Commit e879b2f

Browse files
authored
fix: health check configuration for snmp (#1279)
1 parent ec7bb09 commit e879b2f

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

conf/input.snmp/snmp.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ agents = [
1818

1919
## health check
2020
# 健康检查的周期
21-
# health_check_interval=60s
21+
# health_check_interval="60s"
2222
# 健康检查超时
23-
# health_check_timeout=5s
23+
# health_check_timeout="5s"
2424
# 健康检查失败达到多少次判定设备异常
2525
# max_fail_count=3
2626
# 异常后隔多久再检查
27-
# recovery_interval=5m
27+
# recovery_interval="5m"
2828

2929
## SNMP version; can be 1, 2, or 3.
3030
# version = 2

inputs/snmp/health_check.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (ins *Instance) StartHealthMonitor() {
1515
ins.healthMonitorStarted = true
1616

1717
go func() {
18-
ticker := time.NewTicker(ins.HealthCheckInterval)
18+
ticker := time.NewTicker(time.Duration(ins.HealthCheckInterval))
1919
defer ticker.Stop()
2020

2121
for {
@@ -45,7 +45,7 @@ func (ins *Instance) checkAgentHealth(i int, agent string) {
4545
timeSinceLastCheck := time.Since(status.lastSeen)
4646
status.mu.RUnlock()
4747

48-
if timeSinceLastCheck < ins.RecoveryInterval {
48+
if timeSinceLastCheck < time.Duration(ins.RecoveryInterval) {
4949
return
5050
}
5151
}

inputs/snmp/instances.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ type Instance struct {
5959
healthMonitorStarted bool
6060

6161
// Configuration for health monitoring
62-
HealthCheckInterval time.Duration `toml:"health_check_interval"`
63-
HealthCheckTimeout time.Duration `toml:"health_check_timeout"`
64-
MaxFailCount int `toml:"max_fail_count"`
65-
RecoveryInterval time.Duration `toml:"recovery_interval"`
62+
HealthCheckInterval config.Duration `toml:"health_check_interval"`
63+
HealthCheckTimeout config.Duration `toml:"health_check_timeout"`
64+
MaxFailCount int `toml:"max_fail_count"`
65+
RecoveryInterval config.Duration `toml:"recovery_interval"`
6666

6767
stop chan struct{}
6868
}
@@ -106,16 +106,16 @@ func (ins *Instance) Init() error {
106106
ins.AgentHostTag = "agent_host"
107107
}
108108
if ins.HealthCheckInterval == 0 {
109-
ins.HealthCheckInterval = 60 * time.Second
109+
ins.HealthCheckInterval = config.Duration(60 * time.Second)
110110
}
111111
if ins.HealthCheckTimeout == 0 {
112-
ins.HealthCheckTimeout = 5 * time.Second
112+
ins.HealthCheckTimeout = config.Duration(5 * time.Second)
113113
}
114114
if ins.MaxFailCount == 0 {
115115
ins.MaxFailCount = 3
116116
}
117117
if ins.RecoveryInterval == 0 {
118-
ins.RecoveryInterval = 5 * time.Minute
118+
ins.RecoveryInterval = config.Duration(5 * time.Minute)
119119
}
120120

121121
// Initialize target status tracking

0 commit comments

Comments
 (0)