forked from yvasiyarov/gorelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_metrics.go
110 lines (103 loc) · 2.81 KB
/
memory_metrics.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package gorelic
import (
metrics "github.com/yvasiyarov/go-metrics"
"github.com/yvasiyarov/newrelic_platform_go"
"time"
)
func newMemoryMetricaDataSource(pollInterval int) goMetricaDataSource {
r := metrics.NewRegistry()
metrics.RegisterRuntimeMemStats(r)
metrics.CaptureRuntimeMemStatsOnce(r)
go metrics.CaptureRuntimeMemStats(r, time.Duration(pollInterval)*time.Second)
return goMetricaDataSource{r}
}
func addMemoryMericsToComponent(component newrelic_platform_go.IComponent, pollInterval int) {
gaugeMetrics := []*baseGoMetrica{
//Memory in use metrics
&baseGoMetrica{
name: "InUse/Total",
units: "bytes",
dataSourceKey: "runtime.MemStats.Alloc",
},
&baseGoMetrica{
name: "InUse/Heap",
units: "bytes",
dataSourceKey: "runtime.MemStats.HeapAlloc",
},
&baseGoMetrica{
name: "InUse/Stack",
units: "bytes",
dataSourceKey: "runtime.MemStats.StackInuse",
},
&baseGoMetrica{
name: "InUse/MSpanInuse",
units: "bytes",
dataSourceKey: "runtime.MemStats.MSpanInuse",
},
&baseGoMetrica{
name: "InUse/MCacheInuse",
units: "bytes",
dataSourceKey: "runtime.MemStats.MCacheInuse",
},
}
ds := newMemoryMetricaDataSource(pollInterval)
for _, m := range gaugeMetrics {
m.basePath = "Runtime/Memory/"
m.dataSource = ds
component.AddMetrica(&gaugeMetrica{m})
}
gaugeIncMetrics := []*baseGoMetrica{
//NO operations graph
&baseGoMetrica{
name: "Operations/NoPointerLookups",
units: "lookups",
dataSourceKey: "runtime.MemStats.Lookups",
},
&baseGoMetrica{
name: "Operations/NoMallocs",
units: "mallocs",
dataSourceKey: "runtime.MemStats.Mallocs",
},
&baseGoMetrica{
name: "Operations/NoFrees",
units: "frees",
dataSourceKey: "runtime.MemStats.Frees",
},
// Sytem memory allocations
&baseGoMetrica{
name: "SysMem/Total",
units: "bytes",
dataSourceKey: "runtime.MemStats.Sys",
},
&baseGoMetrica{
name: "SysMem/Heap",
units: "bytes",
dataSourceKey: "runtime.MemStats.HeapSys",
},
&baseGoMetrica{
name: "SysMem/Stack",
units: "bytes",
dataSourceKey: "runtime.MemStats.StackSys",
},
&baseGoMetrica{
name: "SysMem/MSpan",
units: "bytes",
dataSourceKey: "runtime.MemStats.MSpanSys",
},
&baseGoMetrica{
name: "SysMem/MCache",
units: "bytes",
dataSourceKey: "runtime.MemStats.MCacheSys",
},
&baseGoMetrica{
name: "SysMem/BuckHash",
units: "bytes",
dataSourceKey: "runtime.MemStats.BuckHashSys",
},
}
for _, m := range gaugeIncMetrics {
m.basePath = "Runtime/Memory/"
m.dataSource = ds
component.AddMetrica(&gaugeIncMetrica{baseGoMetrica: m})
}
}