2021-06-03 22:29:34 +00:00
|
|
|
// +build !openbsd !arm
|
2021-06-02 17:17:52 +00:00
|
|
|
|
|
|
|
package diagnose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2021-08-02 17:06:04 +00:00
|
|
|
"github.com/dustin/go-humanize"
|
2021-06-02 17:17:52 +00:00
|
|
|
"github.com/shirou/gopsutil/disk"
|
|
|
|
)
|
|
|
|
|
|
|
|
func diskUsage(ctx context.Context) error {
|
|
|
|
// Disk usage
|
|
|
|
partitions, err := disk.Partitions(false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionExcludes := []string{"/boot"}
|
|
|
|
partLoop:
|
|
|
|
for _, partition := range partitions {
|
|
|
|
for _, exc := range partitionExcludes {
|
|
|
|
if strings.HasPrefix(partition.Mountpoint, exc) {
|
|
|
|
continue partLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
usage, err := disk.Usage(partition.Mountpoint)
|
2021-07-11 22:44:19 +00:00
|
|
|
testName := "Check Disk Usage"
|
2021-06-02 17:17:52 +00:00
|
|
|
if err != nil {
|
2021-07-11 22:44:19 +00:00
|
|
|
Warn(ctx, fmt.Sprintf("Could not obtain partition usage for %s: %v.", partition.Mountpoint, err))
|
2021-06-02 17:17:52 +00:00
|
|
|
} else {
|
|
|
|
if usage.UsedPercent > 95 {
|
2021-08-02 21:41:12 +00:00
|
|
|
SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %.2f percent full.", usage.UsedPercent),
|
|
|
|
Advice("It is recommended to have more than five percent of the partition free."))
|
2021-08-02 17:06:04 +00:00
|
|
|
} else if usage.Free < 1<<30 {
|
2021-08-02 21:41:12 +00:00
|
|
|
SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" has %s free.", humanize.Bytes(usage.Free)),
|
|
|
|
Advice("It is recommended to have at least 1 GB of space free per partition."))
|
2021-06-02 17:17:52 +00:00
|
|
|
} else {
|
2021-07-11 22:44:19 +00:00
|
|
|
SpotOk(ctx, testName, partition.Mountpoint+" usage ok.")
|
2021-06-02 17:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|