Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ func executeCheck(event *types.Event) (int, error) {
return sensu.CheckStateCritical, fmt.Errorf("Error obtaining CPU timings: %v", err)
}

startTotal := start[0].User + start[0].System + start[0].Idle + start[0].Nice + start[0].Iowait + start[0].Irq + start[0].Softirq + start[0].Steal + start[0].Guest + start[0].GuestNice

duration, err := time.ParseDuration(fmt.Sprintf("%ds", plugin.Interval))
if err != nil {
return sensu.CheckStateCritical, fmt.Errorf("Error parsing duration: %v", err)
Expand All @@ -95,9 +93,16 @@ func executeCheck(event *types.Event) (int, error) {
return sensu.CheckStateCritical, fmt.Errorf("Error obtaining CPU timings: %v", err)
}

endTotal := end[0].User + end[0].System + end[0].Idle + end[0].Nice + end[0].Iowait + end[0].Irq + end[0].Softirq + end[0].Steal + end[0].Guest + end[0].GuestNice
diff := (end[0].User - start[0].User)
diff += (end[0].System - start[0].System)
diff += (end[0].Idle - start[0].Idle)
diff += (end[0].Nice - start[0].Nice)
diff += (end[0].Iowait - start[0].Iowait)
diff += (end[0].Irq - start[0].Irq)
diff += (end[0].Softirq - start[0].Softirq)
diff += (end[0].Steal - start[0].Steal)
diff += (end[0].GuestNice - start[0].GuestNice)

diff := endTotal - startTotal
idlePct := ((end[0].Idle - start[0].Idle) / diff) * 100
usedPct := 100 - idlePct

Expand Down