forked from Bo0mer/mozzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
containermetrics.go
62 lines (55 loc) · 1.41 KB
/
containermetrics.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
package mozzle
import (
"strconv"
cfevent "github.com/cloudfoundry/sonde-go/events"
)
type containerMetrics struct {
*cfevent.ContainerMetric
App application
}
func (m containerMetrics) EmitTo(e Emitter) {
attributes := attributes(m.App)
attributes["instance"] = strconv.Itoa(int(m.GetInstanceIndex()))
e.Emit(forApp(m.App, Metric{
Service: "memory used_bytes",
Metric: int(m.GetMemoryBytes()),
State: "ok",
Attributes: attributes,
}))
e.Emit(forApp(m.App, Metric{
Service: "memory total_bytes",
Metric: int(m.GetMemoryBytesQuota()),
State: "ok",
Attributes: attributes,
}))
e.Emit(forApp(m.App, Metric{
Service: "memory used_ratio",
Metric: ratio(m.GetMemoryBytes(), m.GetMemoryBytesQuota()),
State: "ok",
Attributes: attributes,
}))
e.Emit(forApp(m.App, Metric{
Service: "disk used_bytes",
Metric: int(m.GetDiskBytes()),
State: "ok",
Attributes: attributes,
}))
e.Emit(forApp(m.App, Metric{
Service: "disk total_bytes",
Metric: int(m.GetDiskBytesQuota()),
State: "ok",
Attributes: attributes,
}))
e.Emit(forApp(m.App, Metric{
Service: "disk used_ratio",
Metric: ratio(m.GetDiskBytes(), m.GetDiskBytesQuota()),
State: "ok",
Attributes: attributes,
}))
e.Emit(forApp(m.App, Metric{
Service: "cpu_percent",
Metric: m.GetCpuPercentage(),
State: "ok",
Attributes: attributes,
}))
}