/
loadavg.go
53 lines (39 loc) · 1.59 KB
/
loadavg.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 main
import (
"fmt"
"errors"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
linuxproc "github.com/c9s/goprocinfo/linux"
)
type loadAverageChecker interface {
Checks() []fthealth.Check
Check() (string, error)
}
type loadAverageCheckerImpl struct{}
func (lac loadAverageCheckerImpl) Checks() []fthealth.Check {
check := fthealth.Check{
BusinessImpact: "A part of the publishing workflow might be affected",
Name: "CPU load average check",
PanicGuide: "https://dewey.ft.com/upp-system-healthcheck.html",
Severity: 2,
TechnicalSummary: "CPU is quite busy lately. This might not be a problem if it happens intermittently, however if it persists consider upgrading or adding new boxes.",
Checker: lac.Check,
}
return []fthealth.Check{check}
}
func (lac loadAverageCheckerImpl) Check() (string, error) {
l, err := linuxproc.ReadLoadAvg(*hostPath + "/proc/loadavg")
if err != nil {
return "", errors.New("Couldn't read loadavg data")
}
cpuInfo, err := linuxproc.ReadCPUInfo(*hostPath + "/proc/cpuinfo")
if err != nil {
return "", errors.New("Couldn't read cpuinfo data")
}
fiveMinLimit := (1.8 * float64(cpuInfo.NumCPU()))
fifteenMinLimit := (1.1 * float64(cpuInfo.NumCPU()))
if l.Last5Min > fiveMinLimit || l.Last15Min > fifteenMinLimit {
return fmt.Sprintf("Last5Min: %2.2f, Last15Min: %2.2f", l.Last5Min, l.Last15Min), fmt.Errorf("Load avg is above the recommended threshold: Last5Min: %2.2f, Last15Min: %2.2f", l.Last5Min, l.Last15Min)
}
return fmt.Sprintf("Last5Min: %2.2f, Last15Min: %2.2f", l.Last5Min, l.Last15Min), nil
}