-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.go
80 lines (65 loc) · 1.67 KB
/
resources.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package psi
import "fmt"
type Resource string
const (
CPU Resource = "cpu"
Memory Resource = "memory"
IO Resource = "io"
)
type Metric string
const (
Avg10 Metric = "avg10"
Avg60 Metric = "avg60"
Avg300 Metric = "avg300"
)
const lineFormat = "avg10=%f avg60=%f avg300=%f total=%d"
// PSILine is a single line of values as returned by `/proc/pressure/*`.
//
// The Avg entries are averages over n seconds, as a percentage.
// The Total line is in microseconds.
type PSILine struct {
Avg10 float64
Avg60 float64
Avg300 float64
Total uint64 // in microseconds, very accurate starvation metric
}
func (l PSILine) GetMetric(metric Metric) float64 {
switch metric {
case Avg10:
return l.Avg10
case Avg60:
return l.Avg60
case Avg300:
return l.Avg300
default:
panic("unexpected metric")
}
}
func (l PSILine) String() string {
return fmt.Sprintf(lineFormat, l.Avg10, l.Avg60, l.Avg300, l.Total)
}
// PSIStats represent pressure stall information from /proc/pressure/*
//
// "Some" indicates the share of time in which at least some tasks are stalled.
// "Full" indicates the share of time in which all non-idle tasks are stalled simultaneously.
type PSIStats struct {
Some *PSILine
Full *PSILine
}
func (s PSIStats) String() string {
return fmt.Sprintf("some %s\nfull %s", s.Some, s.Full)
}
func (s PSIStats) HasFull() bool {
return s.Full != nil
}
type PSIStatsResource struct {
Memory *PSIStats
CPU *PSIStats
IO *PSIStats
}
func (s PSIStatsResource) String() string {
return fmt.Sprintf("memory:\n%s\n\ncpu:\n%s\n\nio:\n%s", s.Memory, s.CPU, s.IO)
}
func ResourceToPath(resource Resource) string {
return fmt.Sprintf("/proc/pressure/%s", resource)
}