forked from yvasiyarov/gorelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gc_metrics.go
65 lines (58 loc) · 1.65 KB
/
gc_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
package gorelic
import (
metrics "github.com/yvasiyarov/go-metrics"
"github.com/yvasiyarov/newrelic_platform_go"
"time"
)
func newGCMetricaDataSource(pollInterval int) goMetricaDataSource {
r := metrics.NewRegistry()
metrics.RegisterDebugGCStats(r)
go metrics.CaptureDebugGCStats(r, time.Duration(pollInterval)*time.Second)
return goMetricaDataSource{r}
}
func addGCMetricsToComponent(component newrelic_platform_go.IComponent, pollInterval int) {
metrics := []*baseGoMetrica{
&baseGoMetrica{
name: "NumberOfGCCalls",
units: "calls",
dataSourceKey: "debug.GCStats.NumGC",
},
&baseGoMetrica{
name: "PauseTotalTime",
units: "nanoseconds",
dataSourceKey: "debug.GCStats.PauseTotal",
},
}
ds := newGCMetricaDataSource(pollInterval)
for _, m := range metrics {
m.basePath = "Runtime/GC/"
m.dataSource = ds
component.AddMetrica(&gaugeMetrica{m})
}
histogramMetrics := []*histogramMetrica{
&histogramMetrica{
statFunction: histogramMax,
baseGoMetrica: &baseGoMetrica{name: "Max"},
},
&histogramMetrica{
statFunction: histogramMin,
baseGoMetrica: &baseGoMetrica{name: "Min"},
},
&histogramMetrica{
statFunction: histogramMean,
baseGoMetrica: &baseGoMetrica{name: "Mean"},
},
&histogramMetrica{
statFunction: histogramPercentile,
percentileValue: 0.95,
baseGoMetrica: &baseGoMetrica{name: "Percentile95"},
},
}
for _, m := range histogramMetrics {
m.baseGoMetrica.units = "nanoseconds"
m.baseGoMetrica.dataSourceKey = "debug.GCStats.Pause"
m.baseGoMetrica.basePath = "Runtime/GC/GCTime/"
m.baseGoMetrica.dataSource = ds
component.AddMetrica(m)
}
}