Skip to content

Commit 6748c7d

Browse files
author
Hridoy Roy
authored
backport disk usage print fixes (#12232)
* backport disk usage print fixes * fix advice
1 parent f882564 commit 6748c7d

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

changelog/12229.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
core: fix byte printing for diagnose disk checks
3+
```

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ require (
4141
github.com/docker/go-connections v0.4.0
4242
github.com/dsnet/compress v0.0.1 // indirect
4343
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74
44+
github.com/dustin/go-humanize v1.0.0
4445
github.com/elazarl/go-bindata-assetfs v1.0.1-0.20200509193318-234c15e7648f
4546
github.com/fatih/color v1.11.0
4647
github.com/fatih/structs v1.1.0

vault/diagnose/os_common.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"strings"
99

10+
"github.com/dustin/go-humanize"
1011
"github.com/shirou/gopsutil/disk"
1112
)
1213

@@ -31,10 +32,10 @@ partLoop:
3132
Warn(ctx, fmt.Sprintf("Could not obtain partition usage for %s: %v.", partition.Mountpoint, err))
3233
} else {
3334
if usage.UsedPercent > 95 {
34-
SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %d percent full.", usage.UsedPercent),
35+
SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %.2f percent full.", usage.UsedPercent),
3536
Advice("It is recommended to have more than five percent of the partition free."))
36-
} else if usage.Free < 2<<30 {
37-
SpotWarn(ctx, testName, partition.Mountpoint+" has %d bytes full.",
37+
} else if usage.Free < 1<<30 {
38+
SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" has %s free.", humanize.Bytes(usage.Free)),
3839
Advice("It is recommended to have at least 1 GB of space free per partition."))
3940
} else {
4041
SpotOk(ctx, testName, partition.Mountpoint+" usage ok.")

0 commit comments

Comments
 (0)