Skip to content

Commit

Permalink
ER 2667: Average_rtt coming to be zero for target in UP state (influx…
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeep-vunet authored Dec 17, 2021
1 parent 4cf7786 commit a19abd1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugins/inputs/snmp_heartbeat/snmp_heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ func (s *Snmp) gatherTable(acc telegraf.Accumulator, gs snmpConnection, t Table,
var rt *RTable
var err error
var avg_rtt = int64(0)
var rtt = int64(0)
var max_rtt = int64(0)
var min_rtt = int64(0)
var jitter = int64(0)
Expand All @@ -472,7 +471,7 @@ func (s *Snmp) gatherTable(acc telegraf.Accumulator, gs snmpConnection, t Table,
start := time.Now()
out_rt, err = t.Build(gs, walk)
time_taken := time.Since(start).Milliseconds()
if time_taken == 0 {
if time_taken < 1 {
time_taken = 1
}
if err != nil {
Expand All @@ -486,6 +485,7 @@ func (s *Snmp) gatherTable(acc telegraf.Accumulator, gs snmpConnection, t Table,
if len(round_time) == 0 {
return err
}
var rtt = int64(0)
max_rtt = round_time[0]
min_rtt = round_time[0]
for index, ele := range round_time {
Expand All @@ -500,12 +500,13 @@ func (s *Snmp) gatherTable(acc telegraf.Accumulator, gs snmpConnection, t Table,
if index+1 < len(round_time) {
jitter_value = jitter_value + (ele - round_time[index+1])
}
avg_rtt = rtt / s.Packets
jitter = jitter_value / (s.Packets - 1)
if jitter < 0 {
jitter = -jitter
}
}
avg_rtt = rtt / s.Packets

pkt_loss_pct = ((float64(s.Packets) - float64(len(round_time))) / float64(s.Packets)) * 100
} else {
rt, err = t.Build(gs, walk)
Expand All @@ -532,6 +533,9 @@ func (s *Snmp) gatherTable(acc telegraf.Accumulator, gs snmpConnection, t Table,
tr.Fields["period"] = period
tr.Fields["target_state"] = "Up"
tr.Fields["method"] = "snmp"
if avg_rtt < 1 {
avg_rtt = 1
}
tr.Fields["average_rtt"] = avg_rtt
tr.Fields["minimum_rtt"] = min_rtt
tr.Fields["maximum_rtt"] = max_rtt
Expand Down

0 comments on commit a19abd1

Please sign in to comment.