Skip to content

Commit

Permalink
Add --human-readable option
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Agbo <[email protected]>
  • Loading branch information
boagg committed Apr 16, 2021
1 parent 228613a commit 2485559
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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.5.0] - 2021-04-16

### Added
- Added --human-readable option to support ignoring human-readable option like df unix/linux command

## [0.4.2] - 2021-03-31

### Changed
Expand Down
4 changes: 4 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)
-H, --human-readable print sizes in powers of 1024 (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,9 @@ 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 `--human-readable` (False by default) option determines if you prefer
to display sizes of different drives in a human format. (Like df Unix/linux
command.)

## Configuration

Expand Down
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
IncludePseudo bool
IncludeReadOnly bool
FailOnError bool
HumanReadable bool
}

var (
Expand Down Expand Up @@ -115,6 +116,16 @@ var (
Usage: "Include read-only filesystems (default false)",
Value: &plugin.IncludeReadOnly,
},
{
Path: "human-readable",
Env: "",
Argument: "human-readable",
Shorthand: "H",
Default: false,
Usage: "print sizes in powers of 1024 (default false)",
Value: &plugin.HumanReadable,
},

}
)

Expand Down Expand Up @@ -189,7 +200,11 @@ func executeCheck(event *types.Event) (int, error) {
} 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))
if plugin.HumanReadable {
fmt.Printf("%s %.2f%% - Total: %s, Used: %s, Free: %s\n", p.Mountpoint, s.UsedPercent, human.IBytes(s.Total), human.IBytes(s.Used), human.IBytes(s.Free))
} else {
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 {
Expand Down

0 comments on commit 2485559

Please sign in to comment.