Skip to content
Merged
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
28 changes: 14 additions & 14 deletions usageplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
return res, nil
}

func minZero(a float64) float64 {
return max(a, 0)
func gapMinZero(a float64, b float64) float64 {

Check warning on line 147 in usageplugin.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Group together these consecutive parameters of the same type.

See more on https://sonarcloud.io/project/issues?id=monitoring-forge_mackerel-plugin-linux-usage&issues=AaDB3a4LmY7AJHD34TkD&open=AaDB3a4LmY7AJHD34TkD&pullRequest=24
return max(a-b, 0)
}

func (o *Opt) cpuMetrics(pf procfs.FS) (map[string]float64, error) {
Expand Down Expand Up @@ -185,41 +185,41 @@

var total float64
// User
gapUser := minZero(float64(curCPU.User) - float64(prevCPU.User))
gapUser := gapMinZero(curCPU.User, prevCPU.User)
total += gapUser
// Nice
gapNice := minZero(float64(curCPU.Nice) - float64(prevCPU.Nice))
gapNice := gapMinZero(curCPU.Nice, prevCPU.Nice)
total += gapNice
// System
gapSystem := minZero(float64(curCPU.System) - float64(prevCPU.System))
gapSystem := gapMinZero(curCPU.System, prevCPU.System)
total += gapSystem
// Idle
gapIdle := minZero(float64(curCPU.Idle) - float64(prevCPU.Idle))
gapIdle := gapMinZero(curCPU.Idle, prevCPU.Idle)
total += gapIdle
// Iowait
gapIowait := minZero(float64(curCPU.Iowait) - float64(prevCPU.Iowait))
gapIowait := gapMinZero(curCPU.Iowait, prevCPU.Iowait)
total += gapIowait
// Irq
gapIRQ := minZero(float64(curCPU.IRQ) - float64(prevCPU.IRQ))
gapIRQ := gapMinZero(curCPU.IRQ, prevCPU.IRQ)
total += gapIRQ
// SoftIRQ
gapSoftIRQ := minZero(float64(curCPU.SoftIRQ) - float64(prevCPU.SoftIRQ))
gapSoftIRQ := gapMinZero(curCPU.SoftIRQ, prevCPU.SoftIRQ)
total += gapSoftIRQ
// Steal
gapSteal := minZero(float64(curCPU.Steal) - float64(prevCPU.Steal))
gapSteal := gapMinZero(curCPU.Steal, prevCPU.Steal)
total += gapSteal
// Guest
gapGuest := minZero(float64(curCPU.Guest) - float64(prevCPU.Guest))
gapGuest := gapMinZero(curCPU.Guest, prevCPU.Guest)
total += gapGuest
// GuestNice
gapGuestNice := minZero(float64(curCPU.GuestNice) - float64(prevCPU.GuestNice))
gapGuestNice := gapMinZero(curCPU.GuestNice, prevCPU.GuestNice)
total += gapGuestNice

// User includes Guest
gapUser = minZero(gapUser - gapGuest)
gapUser = gapMinZero(gapUser, gapGuest)
total -= gapGuest
// Nice includes GuestNice
gapNice = minZero(gapNice - gapGuestNice)
gapNice = gapMinZero(gapNice, gapGuestNice)
total -= gapGuestNice

if total <= 0 {
Expand Down
Loading