From 93cd3fad9f871c0e8f553d024546d82afcdd9f5b Mon Sep 17 00:00:00 2001 From: Steven Agbo Date: Fri, 16 Apr 2021 15:53:27 +0200 Subject: [PATCH] Add --inode-mode option Signed-off-by: Steven Agbo --- CHANGELOG.md | 5 +++++ README.md | 2 ++ main.go | 52 +++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2fb77e..aaee87a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index ca0d275..70a407c 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/main.go b/main.go index d357412..0f82550 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "strings" + "strconv" human "github.com/dustin/go-humanize" "github.com/sensu-community/sensu-plugin-sdk/sensu" @@ -22,6 +23,7 @@ type Config struct { IncludePseudo bool IncludeReadOnly bool FailOnError bool + InodeMode bool } var ( @@ -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, + }, + } ) @@ -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