forked from jacksontj/mongodb_exporter
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tcmalloc.go
132 lines (112 loc) · 5.52 KB
/
tcmalloc.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package collector
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
tcmallocGeneral = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tcmalloc_generic_heap",
Help: "High-level summary metricsInternal metrics from tcmalloc",
}, []string{"type"})
tcmallocPageheapBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tcmalloc_pageheap_bytes",
Help: "Sizes for tcpmalloc pageheaps",
}, []string{"type"})
tcmallocPageheapCounts = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tcmalloc_pageheap_count",
Help: "Sizes for tcpmalloc pageheaps",
}, []string{"type"})
tcmallocCacheBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tcmalloc_cache_bytes",
Help: "Sizes for tcpmalloc caches in bytes",
}, []string{"cache", "type"})
tcmallocAggressiveDecommit = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tcmalloc_aggressive_memory_decommit",
Help: "Whether aggressive_memory_decommit is on",
})
tcmallocSpinlogkTotalDelayNs = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tcmalloc_spinlock_total_delay_ns",
Help: "Total ns spent on the tcmalloc spinlock",
})
tcmallocFreeBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "tcmalloc_free_bytes",
Help: "Total free bytes of tcmalloc",
})
)
// TCMallocStats tracks the mem stats metrics.
type TCMallocStats struct {
Generic GenericTCMAllocStats `bson:"generic"`
Details DetailedTCMallocStats `bson:"tcmalloc"`
}
type GenericTCMAllocStats struct {
CurrentAllocatedBytes float64 `bson:"current_allocated_bytes"`
HeapSize float64 `bson:"heap_size"`
}
type DetailedTCMallocStats struct {
PageheapFreeBytes float64 `bson:"pageheap_free_bytes"`
PageheapUnmappedBytes float64 `bson:"pageheap_unmapped_bytes"`
PageheapComittedBytes float64 `bson:"pageheap_committed_bytes"`
PageheapScavengeCount float64 `bson:"pageheap_scavenge_count"`
PageheapCommitCount float64 `bson:"pageheap_commit_count"`
PageheapTotalCommitBytes float64 `bson:"pageheap_total_commit_bytes"`
PageheapDecommitCount float64 `bson:"pageheap_decommit_count"`
PageheapTotalDecommitBytes float64 `bson:"pageheap_total_decommit_bytes"`
PageheapReserveCount float64 `bson:"pageheap_reserve_count"`
PageheapTotalReserveBytes float64 `bson:"pageheap_total_reserve_bytes"`
SpinlockTotalDelayNS float64 `bson:"spinlock_total_delay_ns"`
MaxTotalThreadCacheBytes float64 `bson:"max_total_thread_cache_bytes"`
CurrentTotalThreadCacheBytes float64 `bson:"current_total_thread_cache_bytes"`
CentralCacheFreeBytes float64 `bson:"central_cache_free_bytes"`
TransferCacheFreeBytes float64 `bson:"transfer_cache_free_bytes"`
ThreadCacheFreeBytes float64 `bson:"thread_cache_free_bytes"`
TotalFreeBytes float64 `bson:"total_free_bytes"`
AggressiveMemoryDecommit float64 `bson:"aggressive_memory_decommit"`
}
// Export exports the data to prometheus.
func (m *TCMallocStats) Export(ch chan<- prometheus.Metric) {
// Generic metrics
tcmallocGeneral.WithLabelValues("allocated").Set(m.Generic.CurrentAllocatedBytes)
tcmallocGeneral.WithLabelValues("total").Set(m.Generic.HeapSize)
tcmallocGeneral.Collect(ch)
// Pageheap
tcmallocPageheapBytes.WithLabelValues("free").Set(m.Details.PageheapFreeBytes)
tcmallocPageheapBytes.WithLabelValues("unmapped").Set(m.Details.PageheapUnmappedBytes)
tcmallocPageheapBytes.WithLabelValues("comitted").Set(m.Details.PageheapComittedBytes)
tcmallocPageheapBytes.WithLabelValues("total_commit").Set(m.Details.PageheapTotalCommitBytes)
tcmallocPageheapBytes.WithLabelValues("total_decommit").Set(m.Details.PageheapTotalDecommitBytes)
tcmallocPageheapBytes.WithLabelValues("total_reserve").Set(m.Details.PageheapTotalReserveBytes)
tcmallocPageheapBytes.Collect(ch)
tcmallocPageheapCounts.WithLabelValues("scavenge").Set(m.Details.PageheapScavengeCount)
tcmallocPageheapCounts.WithLabelValues("commit").Set(m.Details.PageheapCommitCount)
tcmallocPageheapCounts.WithLabelValues("decommit").Set(m.Details.PageheapDecommitCount)
tcmallocPageheapCounts.WithLabelValues("reserve").Set(m.Details.PageheapReserveCount)
tcmallocPageheapCounts.Collect(ch)
tcmallocCacheBytes.WithLabelValues("thread_cache", "max_total").Set(m.Details.MaxTotalThreadCacheBytes)
tcmallocCacheBytes.WithLabelValues("thread_cache", "current_total").Set(m.Details.CurrentTotalThreadCacheBytes)
tcmallocCacheBytes.WithLabelValues("central_cache", "free").Set(m.Details.CentralCacheFreeBytes)
tcmallocCacheBytes.WithLabelValues("transfer_cache", "free").Set(m.Details.TransferCacheFreeBytes)
tcmallocCacheBytes.WithLabelValues("thread_cache", "free").Set(m.Details.ThreadCacheFreeBytes)
tcmallocCacheBytes.Collect(ch)
tcmallocAggressiveDecommit.Set(m.Details.AggressiveMemoryDecommit)
tcmallocAggressiveDecommit.Collect(ch)
tcmallocSpinlogkTotalDelayNs.Set(m.Details.SpinlockTotalDelayNS)
tcmallocSpinlogkTotalDelayNs.Collect(ch)
tcmallocFreeBytes.Set(m.Details.TotalFreeBytes)
tcmallocFreeBytes.Collect(ch)
}
// Describe describes the metrics for prometheus
func (m *TCMallocStats) Describe(ch chan<- *prometheus.Desc) {
tcmallocGeneral.Describe(ch)
tcmallocPageheapBytes.Describe(ch)
tcmallocPageheapCounts.Describe(ch)
tcmallocCacheBytes.Describe(ch)
tcmallocAggressiveDecommit.Describe(ch)
tcmallocSpinlogkTotalDelayNs.Describe(ch)
tcmallocFreeBytes.Describe(ch)
}