Skip to content

Commit

Permalink
Merge 94e20dc into 7b4ef08
Browse files Browse the repository at this point in the history
  • Loading branch information
susisu committed Dec 17, 2018
2 parents 7b4ef08 + 94e20dc commit 9bbf51c
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions check-disk/lib/check-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,34 @@ type unit struct {

func checkStatus(current checkers.Status, threshold string, units float64, disk *gpud.UsageStat, chkInode bool, status checkers.Status) (checkers.Status, error) {
if strings.HasSuffix(threshold, "%") {
v, err := strconv.ParseFloat(strings.TrimRight(threshold, "%"), 64)
thresholdPct, err := strconv.ParseFloat(strings.TrimRight(threshold, "%"), 64)
if err != nil {
return checkers.UNKNOWN, err
}

freePct := float64(100) - disk.UsedPercent

inodesFreePct := float64(100) - disk.InodesUsedPercent
if float64(disk.InodesTotal) == float64(0) {
inodesFreePct = float64(0)
}

if chkInode && v > inodesFreePct {
// Skip checking if disk.InodesTotal == 0 since inodesFreePct is meaningless.
if chkInode && (disk.InodesTotal != 0 && thresholdPct > inodesFreePct) {
current = status
}

if !chkInode && (v > freePct || v > inodesFreePct) {
if !chkInode && (thresholdPct > freePct || (disk.InodesTotal != 0 && thresholdPct > inodesFreePct)) {
current = status
}
} else {
if chkInode {
return checkers.UNKNOWN, errors.New("-W, -K value should be N%")
}

v, err := strconv.ParseFloat(threshold, 64)
thresholdVal, err := strconv.ParseFloat(threshold, 64)
if err != nil {
return checkers.UNKNOWN, err
}

free := float64(disk.Free) / units
if v > free {
if thresholdVal > free {
current = status
}
}
Expand Down Expand Up @@ -280,12 +277,12 @@ func filterPartitionsByInclusion(partitions []gpud.PartitionStat, list []string,
for _, partition := range partitions {
var ok = false
for _, l := range list {
if (l == key(partition)) {
if l == key(partition) {
ok = true
break
}
}
if (ok) {
if ok {
newPartitions = append(newPartitions, partition)
}
}
Expand All @@ -298,12 +295,12 @@ func filterPartitionsByExclusion(partitions []gpud.PartitionStat, list []string,
for _, partition := range partitions {
var ok = true
for _, l := range list {
if (l == key(partition)) {
if l == key(partition) {
ok = false
break
}
}
if (ok) {
if ok {
newPartitions = append(newPartitions, partition)
}
}
Expand Down

0 comments on commit 9bbf51c

Please sign in to comment.