Skip to content

Commit

Permalink
Check pointers for nil before dereferencing
Browse files Browse the repository at this point in the history
  • Loading branch information
poblahblahblah committed Sep 15, 2017
1 parent 33fe1f0 commit c84861a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plugins/inputs/nginx_plus/nginx_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,16 @@ func (s *Status) Gather(tags map[string]string, acc telegraf.Accumulator) {
}

func (s *Status) gatherProcessesMetrics(tags map[string]string, acc telegraf.Accumulator) {
var respawned int

if s.Processes.Respawned != nil {
respawned = *s.Processes.Respawned
}

acc.AddFields(
"nginx_plus_processes",
map[string]interface{}{
"respawned": *s.Processes.Respawned,
"respawned": respawned,
},
tags,
)
Expand Down Expand Up @@ -390,6 +396,12 @@ func (s *Status) gatherUpstreamMetrics(tags map[string]string, acc telegraf.Accu
upstreamTags,
)
for _, peer := range upstream.Peers {
var selected int64

if peer.Selected != nil {
selected = *peer.Selected
}

peerFields := map[string]interface{}{
"backup": peer.Backup,
"weight": peer.Weight,
Expand All @@ -411,7 +423,7 @@ func (s *Status) gatherUpstreamMetrics(tags map[string]string, acc telegraf.Accu
"healthchecks_unhealthy": peer.HealthChecks.Unhealthy,
"downtime": peer.Downtime,
"downstart": peer.Downstart,
"selected": *peer.Selected,
"selected": selected,
}
if peer.HealthChecks.LastPassed != nil {
peerFields["healthchecks_last_passed"] = *peer.HealthChecks.LastPassed
Expand Down

0 comments on commit c84861a

Please sign in to comment.