Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion pkg/snclient/check_drivesize.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,19 @@ func (l *CheckDrivesize) addMetrics(drive string, check *CheckData, usage *disk.
check.critThreshold = check.TransformMultipleKeywords([]string{"free_pct", "free_bytes"}, "free", check.critThreshold)
check.AddBytePercentMetrics("free", drive+" free", magic*float64(usage.Free), magic*float64(total))
}
if check.HasThreshold("used") || check.HasThreshold("used_pct") || check.HasThreshold("used_bytes") {

// convert '<drive> used_pct' keywords in conditions to '<drive> used %' as that matches the metric name
convertDriveUsagePctMetric1 := fmt.Sprintf("%s used_pct", drive)
// metrics are normally added if the operand is simply 'used' , 'used_pct' , 'used_bytes' etc. and do not have a drive prefix
// detect conditions where the operand is named '<drive> used %', this is the default way snclient names percent usage metrics.
// if there is a condition using that as an operand, add usage metrics for that drive as well. during the metrics condition checking, they will take effect.
// this helps to check usage metrics specific to drives.
driveUsagePctMetric := fmt.Sprintf("%s used %%", drive)

check.warnThreshold = check.TransformMultipleKeywords([]string{convertDriveUsagePctMetric1}, driveUsagePctMetric, check.warnThreshold)
check.critThreshold = check.TransformMultipleKeywords([]string{convertDriveUsagePctMetric1}, driveUsagePctMetric, check.critThreshold)

if check.HasThreshold(driveUsagePctMetric) || check.HasThreshold("used") || check.HasThreshold("used_pct") || check.HasThreshold("used_bytes") {
check.warnThreshold = check.TransformMultipleKeywords([]string{"used_pct", "used_bytes"}, "used", check.warnThreshold)
check.critThreshold = check.TransformMultipleKeywords([]string{"used_pct", "used_bytes"}, "used", check.critThreshold)
check.AddBytePercentMetrics("used", drive+" used", magic*float64(usage.Used), magic*float64(total))
Expand Down
7 changes: 6 additions & 1 deletion pkg/snclient/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ func NewCondition(input string, attr *[]CheckAttribute) (*Condition, error) {

func (c *Condition) String() string {
if c.original != "" {
return c.original
// keyword might have been changed by a transform function, print it out separately if that is the case
if strings.Contains(c.original, c.keyword) {
return c.original
}

return fmt.Sprintf("(original: %s | keyword: %s)", c.original, c.keyword)
}

if len(c.group) > 0 {
Expand Down
Loading