Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --inode-mode option #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

## [0.6.0] - 2021-04-16

### Added
- Added --inode-mode option to monitore inode information instead of block usage (df -i)

## [0.4.2] - 2021-03-31

### Changed
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Flags:
-p, --include-pseudo-fs Include pseudo-filesystems (e.g. tmpfs) (default false)
-r, --include-read-only Include read-only filesystems (default false)
-f, --fail-on-error Fail and exit on errors getting file system usage (e.g. permission denied) (default false)
-j, --inode-mode Inode mode, check usage of inode (default false)
-h, --help help for check-disk-usage

Use "check-disk-usage [command] --help" for more information about a command.
Expand Down Expand Up @@ -75,6 +76,7 @@ error, such as `permission denied` for a file system. If true, the check will
exit with as a critical failure and provide the error message. If false (the
defaut), it will specify unknown for that file system, provide the error and
continue to check the remaining file systems as expected.
* The `--inode-mode` option check inode information instead of block usage

## Configuration

Expand Down
52 changes: 41 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"strings"
"strconv"

human "github.com/dustin/go-humanize"
"github.com/sensu-community/sensu-plugin-sdk/sensu"
Expand All @@ -22,6 +23,7 @@ type Config struct {
IncludePseudo bool
IncludeReadOnly bool
FailOnError bool
InodeMode bool
}

var (
Expand Down Expand Up @@ -115,6 +117,16 @@ var (
Usage: "Include read-only filesystems (default false)",
Value: &plugin.IncludeReadOnly,
},
{
Path: "inode-mode",
Env: "",
Argument: "inode-mode",
Shorthand: "j",
Default: false,
Usage: "Inode mode, check usage of inode (default false)",
Value: &plugin.InodeMode,
},

}
)

Expand Down Expand Up @@ -178,19 +190,37 @@ func executeCheck(event *types.Event) (int, error) {
continue
}

// implement magic factor for larger file systems?
fmt.Printf("%s ", plugin.PluginConfig.Name)
if s.UsedPercent >= plugin.Critical {
criticals++
fmt.Printf("CRITICAL: ")
} else if s.UsedPercent >= plugin.Warning {
warnings++
fmt.Printf(" WARNING: ")
if plugin.InodeMode {

// implement magic factor for larger file systems?
fmt.Printf("%s ", plugin.PluginConfig.Name)
if s.InodesUsedPercent >= plugin.Critical {
criticals++
fmt.Printf("CRITICAL: ")
} else if s.InodesUsedPercent >= plugin.Warning {
warnings++
fmt.Printf(" WARNING: ")
} else {
fmt.Printf(" OK: ")
}
fmt.Printf("%s %.2f%% - Total: %s, Used: %s, Free: %s\n", p.Mountpoint, s.InodesUsedPercent, strconv.FormatUint(s.InodesTotal, 10), strconv.FormatUint(s.InodesUsed, 10), strconv.FormatUint(s.InodesFree, 10))
} else {
fmt.Printf(" OK: ")

// implement magic factor for larger file systems?
fmt.Printf("%s ", plugin.PluginConfig.Name)
if s.UsedPercent >= plugin.Critical {
criticals++
fmt.Printf("CRITICAL: ")
} else if s.UsedPercent >= plugin.Warning {
warnings++
fmt.Printf(" WARNING: ")
} else {
fmt.Printf(" OK: ")
}
fmt.Printf("%s %.2f%% - Total: %s, Used: %s, Free: %s\n", p.Mountpoint, s.UsedPercent, human.Bytes(s.Total), human.Bytes(s.Used), human.Bytes(s.Free))
}
fmt.Printf("%s %.2f%% - Total: %s, Used: %s, Free: %s\n", p.Mountpoint, s.UsedPercent, human.Bytes(s.Total), human.Bytes(s.Used), human.Bytes(s.Free))
}

}

if criticals > 0 {
return sensu.CheckStateCritical, nil
Expand Down