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

implement magic rescaling of thresholds for large filesystems #14

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
- name: Set up Go 1.18.x
uses: actions/setup-go@v1
with:
go-version: 1.14.x
go-version: 1.18.x
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go 1.14
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: 1.18
id: go
- name: Test
run: go test -v ./...
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ builds:
env:
- CGO_ENABLED=0
main: main.go
ldflags: '-s -w -X github.com/sensu-community/sensu-plugin-sdk/version.version={{.Version}} -X github.com/sensu-community/sensu-plugin-sdk/version.commit={{.Commit}} -X github.com/sensu-community/sensu-plugin-sdk/version.date={{.Date}}'
ldflags: '-s -w -X github.com/sensu/sensu-plugin-sdk/version.version={{.Version}} -X github.com/sensu/sensu-plugin-sdk/version.commit={{.Commit}} -X github.com/sensu/sensu-plugin-sdk/version.date={{.Date}}'
# Set the binary output location to bin/ so archive will comply with Sensu Go Asset structure
binary: bin/{{ .ProjectName }}
goos:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Implement magic scaling factor for large filesystems similar to original ruby plugin.

### Fixed
- corrected armv7 asset build filter in .bonsai.yml. Thanks @DJM0.


## [0.7.0] - 2022-04-06

### Fixed
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ 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)
-m, --magic float Magic factor to adjust warn/crit thresholds. Example: .9 (default 1)
-l, --minimum float Minimum size to adjust (in GiB) (default 100)
-n, --normal float Value in GiB. Levels are not adapted for filesystems of exactly this size, where levels are reduced for smaller filesystems and raised for larger filesystems. (default 20)
-H, --human-readable print sizes in powers of 1024 (default false)
--metrics Output metrics instead of human readable output
--tags strings Comma separated list of additional metrics tags using key=value format.
Expand Down Expand Up @@ -81,6 +84,27 @@ 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.)
* The `--magic`, `--normal`, and `--minimum` options work together to adjust
thresholds for larger filesystems. When a filesystem is larger than `--minimum`
the `--magic` scaling factor is used. For filesystems larger than `--normal` a magic scaling
factor less than 1 increases warning and critical thresholds. On filesystems
smaller than `--normal`, a magic scaling factor less than 1 descreases thesholds.
The idea being there's a bit more/less margin available for filesystems
larger/smaller relative to `--normal` based on similar data accomulation patterns, so the magic scaling factor lets you set a `normal` threshold and adjust the warning and critical thresholds up or down using a calculation. The default `--magic` value, 1.0, will not adapt threshold percentages for volumes.

#### Magic Scaling Calculation

```
normalized_disk_size = disk_size_GiB/normal_size_GiB
rescaled_disk_size = (normalized_disk_size)^magic_scale_factor
scale = rescaled_disk_size / normalized_disk_size
new_percent_threhold = 100.0 - ((100.0 - original_percent_threshold) * scale)
```

* For disks larger than `--normal` and `--magic` values less than 1,
result in `scale < 1` and `new_percent_threshold > original_percent_threshold`
* For disks smaller than `--normal`and `--magic` values less than 1 result in `scale > 1`
result in `scale > 1` and `new_percent_threshold < original_percent_threshold`

## Configuration

Expand Down
57 changes: 49 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
module github.com/nixwiz/check-disk-usage
module github.com/sensu/check-disk-usage

go 1.14
go 1.18

require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/dustin/go-humanize v1.0.0
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/sensu-community/sensu-plugin-sdk v0.11.0
github.com/sensu/sensu-go/api/core/v2 v2.3.0
github.com/sensu/sensu-go/types v0.3.0
github.com/sensu/sensu-go/api/core/v2 v2.14.0
github.com/sensu/sensu-plugin-sdk v0.16.0
github.com/shirou/gopsutil v3.20.11+incompatible
github.com/stretchr/testify v1.6.0
golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f // indirect
)

require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/echlebek/timeproxy v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sensu/sensu-go/types v0.10.0 // indirect
github.com/sensu/sensu-licensing v0.1.2 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
Loading