-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisk-space.go
39 lines (30 loc) · 985 Bytes
/
disk-space.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"github.com/ricochet2200/go-disk-usage/du"
)
// DiskThreshold is the threshold for disk space
const DiskThreshold = 90
// DiskWarningThreshold is the warning threshold for disk space
const DiskWarningThreshold = 75
// MB is a megabyte
var MB = uint64(1024)
// checkDiskSpace performs the disk space check
func checkDiskSpace(disk string) (bool, string, string, int, error) {
usage := du.NewDiskUsage(disk)
msg := fmt.Sprintf("%s: Available: %d MB; Total: %d MB, Usage: %.2f%%", disk, usage.Available()/(MB*MB), usage.Size()/(MB*MB), usage.Usage()*100)
okay := true
newStatusID := 1
// send false if less than 10% disk space left
if usage.Usage()*100 > DiskThreshold {
// problem
okay = false
newStatusID = 2
} else if usage.Usage()*100 > DiskWarningThreshold {
// warning
okay = false
newStatusID = 4
}
data := fmt.Sprintf("%d|%d", usage.Available()/(MB*MB), usage.Size()/(MB*MB))
return okay, msg, data, newStatusID, nil
}