-
Notifications
You must be signed in to change notification settings - Fork 7
/
system.go
53 lines (48 loc) · 1.05 KB
/
system.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
50
51
52
53
// Package uptime provides uptime-related health Checks.
package uptime
import (
"github.com/nelkinda/health-go"
"net/http"
"syscall"
"time"
)
type system struct {
}
func (u *system) HealthChecks() map[string][]health.Checks {
si := &syscall.Sysinfo_t{}
err := syscall.Sysinfo(si)
now := time.Now().UTC().Format(time.RFC3339Nano)
var uptime func() health.Checks
if err != nil {
uptime = func() health.Checks {
return health.Checks{
ComponentType: "system",
Status: health.Fail,
Output: err.Error(),
Time: now,
}
}
} else {
uptime = func() health.Checks {
return health.Checks{
ComponentType: "system",
ObservedValue: si.Uptime,
ObservedUnit: "s",
Status: health.Pass,
Time: now,
}
}
}
return map[string][]health.Checks{
"uptime": {
uptime(),
},
}
}
func (*system) AuthorizeHealth(r *http.Request) bool {
return true
}
// System returns a ChecksProvider for health checks about the system uptime.
func System() health.ChecksProvider {
return &system{}
}