/
meminfo.go
45 lines (37 loc) · 1.25 KB
/
meminfo.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
package main
import (
"fmt"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
linuxproc "github.com/c9s/goprocinfo/linux"
)
type memoryChecker interface {
Checks() []fthealth.Check
AvMemoryCheck() (string, error)
}
type memoryCheckerImpl struct {
thresholdPercent float64
}
func (mc memoryCheckerImpl) Checks() []fthealth.Check {
check := fthealth.Check{
BusinessImpact: "A part of the publishing workflow might be affected",
Name: "Memory load check",
PanicGuide: "https://dewey.ft.com/upp-system-healthcheck.html",
Severity: 2,
TechnicalSummary: "Check the memory usage of services/containers on this host, please confirm these values.",
Checker: mc.AvMemoryCheck,
}
return []fthealth.Check{check}
}
func (mc memoryCheckerImpl) AvMemoryCheck() (string, error) {
meminfo, err := linuxproc.ReadMemInfo(*hostPath + "/proc/meminfo")
if err != nil {
return "", err
}
available := meminfo.MemAvailable
total := meminfo.MemTotal
availablePercent := float64(available) / float64(total) * 100
if availablePercent < mc.thresholdPercent {
return fmt.Sprintf("%2.1f%%", availablePercent), fmt.Errorf("Low available memory: %2.1f%%", availablePercent)
}
return fmt.Sprintf("%2.1f%%", availablePercent), nil
}