-
Notifications
You must be signed in to change notification settings - Fork 1
/
health.go
49 lines (37 loc) · 891 Bytes
/
health.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
40
41
42
43
44
45
46
47
48
49
package fairway
import (
"github.com/shirou/gopsutil/disk"
)
type healthData struct {
Status string `json:"status"`
Details map[string]interface{} `json:"details"`
}
type diskSpace struct {
Status string `json:"status"`
Details map[string]uint64 `json:"details"`
}
func health() ([]byte, error) {
health := healthData{Status: "UP"}
det := map[string]interface{}{}
ds, err := getDiskSpace()
if err != nil {
return []byte(""), err
}
det["diskSpace"] = ds
health.Details = det
return toJSON(health), nil
}
func getDiskSpace() (diskSpace, error) {
diskStat, err := disk.Usage("/")
if err != nil {
return diskSpace{}, err
}
diskSpace := diskSpace{}
d := map[string]uint64{}
d["free"] = diskStat.Free
d["used"] = diskStat.Used
d["total"] = diskStat.Total
d["threashold"] = 10485760
diskSpace.Details = d
return diskSpace, nil
}