|
@@ -2,6 +2,7 @@ package metrics
|
|
|
|
|
|
import (
|
|
import (
|
|
"runtime"
|
|
"runtime"
|
|
|
|
+ "runtime/pprof"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -9,35 +10,37 @@ var (
|
|
memStats runtime.MemStats
|
|
memStats runtime.MemStats
|
|
runtimeMetrics struct {
|
|
runtimeMetrics struct {
|
|
MemStats struct {
|
|
MemStats struct {
|
|
- Alloc Gauge
|
|
|
|
- BuckHashSys Gauge
|
|
|
|
- DebugGC Gauge
|
|
|
|
- EnableGC Gauge
|
|
|
|
- Frees Gauge
|
|
|
|
- HeapAlloc Gauge
|
|
|
|
- HeapIdle Gauge
|
|
|
|
- HeapInuse Gauge
|
|
|
|
- HeapObjects Gauge
|
|
|
|
- HeapReleased Gauge
|
|
|
|
- HeapSys Gauge
|
|
|
|
- LastGC Gauge
|
|
|
|
- Lookups Gauge
|
|
|
|
- Mallocs Gauge
|
|
|
|
- MCacheInuse Gauge
|
|
|
|
- MCacheSys Gauge
|
|
|
|
- MSpanInuse Gauge
|
|
|
|
- MSpanSys Gauge
|
|
|
|
- NextGC Gauge
|
|
|
|
- NumGC Gauge
|
|
|
|
- PauseNs Histogram
|
|
|
|
- PauseTotalNs Gauge
|
|
|
|
- StackInuse Gauge
|
|
|
|
- StackSys Gauge
|
|
|
|
- Sys Gauge
|
|
|
|
- TotalAlloc Gauge
|
|
|
|
|
|
+ Alloc Gauge
|
|
|
|
+ BuckHashSys Gauge
|
|
|
|
+ DebugGC Gauge
|
|
|
|
+ EnableGC Gauge
|
|
|
|
+ Frees Gauge
|
|
|
|
+ HeapAlloc Gauge
|
|
|
|
+ HeapIdle Gauge
|
|
|
|
+ HeapInuse Gauge
|
|
|
|
+ HeapObjects Gauge
|
|
|
|
+ HeapReleased Gauge
|
|
|
|
+ HeapSys Gauge
|
|
|
|
+ LastGC Gauge
|
|
|
|
+ Lookups Gauge
|
|
|
|
+ Mallocs Gauge
|
|
|
|
+ MCacheInuse Gauge
|
|
|
|
+ MCacheSys Gauge
|
|
|
|
+ MSpanInuse Gauge
|
|
|
|
+ MSpanSys Gauge
|
|
|
|
+ NextGC Gauge
|
|
|
|
+ NumGC Gauge
|
|
|
|
+ GCCPUFraction GaugeFloat64
|
|
|
|
+ PauseNs Histogram
|
|
|
|
+ PauseTotalNs Gauge
|
|
|
|
+ StackInuse Gauge
|
|
|
|
+ StackSys Gauge
|
|
|
|
+ Sys Gauge
|
|
|
|
+ TotalAlloc Gauge
|
|
}
|
|
}
|
|
NumCgoCall Gauge
|
|
NumCgoCall Gauge
|
|
NumGoroutine Gauge
|
|
NumGoroutine Gauge
|
|
|
|
+ NumThread Gauge
|
|
ReadMemStats Timer
|
|
ReadMemStats Timer
|
|
}
|
|
}
|
|
frees uint64
|
|
frees uint64
|
|
@@ -45,6 +48,8 @@ var (
|
|
mallocs uint64
|
|
mallocs uint64
|
|
numGC uint32
|
|
numGC uint32
|
|
numCgoCalls int64
|
|
numCgoCalls int64
|
|
|
|
+
|
|
|
|
+ threadCreateProfile = pprof.Lookup("threadcreate")
|
|
)
|
|
)
|
|
|
|
|
|
// Capture new values for the Go runtime statistics exported in
|
|
// Capture new values for the Go runtime statistics exported in
|
|
@@ -97,6 +102,7 @@ func CaptureRuntimeMemStatsOnce(r Registry) {
|
|
runtimeMetrics.MemStats.MSpanSys.Update(int64(memStats.MSpanSys))
|
|
runtimeMetrics.MemStats.MSpanSys.Update(int64(memStats.MSpanSys))
|
|
runtimeMetrics.MemStats.NextGC.Update(int64(memStats.NextGC))
|
|
runtimeMetrics.MemStats.NextGC.Update(int64(memStats.NextGC))
|
|
runtimeMetrics.MemStats.NumGC.Update(int64(memStats.NumGC - numGC))
|
|
runtimeMetrics.MemStats.NumGC.Update(int64(memStats.NumGC - numGC))
|
|
|
|
+ runtimeMetrics.MemStats.GCCPUFraction.Update(gcCPUFraction(&memStats))
|
|
|
|
|
|
// <https://code.google.com/p/go/source/browse/src/pkg/runtime/mgc0.c>
|
|
// <https://code.google.com/p/go/source/browse/src/pkg/runtime/mgc0.c>
|
|
i := numGC % uint32(len(memStats.PauseNs))
|
|
i := numGC % uint32(len(memStats.PauseNs))
|
|
@@ -132,6 +138,8 @@ func CaptureRuntimeMemStatsOnce(r Registry) {
|
|
numCgoCalls = currentNumCgoCalls
|
|
numCgoCalls = currentNumCgoCalls
|
|
|
|
|
|
runtimeMetrics.NumGoroutine.Update(int64(runtime.NumGoroutine()))
|
|
runtimeMetrics.NumGoroutine.Update(int64(runtime.NumGoroutine()))
|
|
|
|
+
|
|
|
|
+ runtimeMetrics.NumThread.Update(int64(threadCreateProfile.Count()))
|
|
}
|
|
}
|
|
|
|
|
|
// Register runtimeMetrics for the Go runtime statistics exported in runtime and
|
|
// Register runtimeMetrics for the Go runtime statistics exported in runtime and
|
|
@@ -158,6 +166,7 @@ func RegisterRuntimeMemStats(r Registry) {
|
|
runtimeMetrics.MemStats.MSpanSys = NewGauge()
|
|
runtimeMetrics.MemStats.MSpanSys = NewGauge()
|
|
runtimeMetrics.MemStats.NextGC = NewGauge()
|
|
runtimeMetrics.MemStats.NextGC = NewGauge()
|
|
runtimeMetrics.MemStats.NumGC = NewGauge()
|
|
runtimeMetrics.MemStats.NumGC = NewGauge()
|
|
|
|
+ runtimeMetrics.MemStats.GCCPUFraction = NewGaugeFloat64()
|
|
runtimeMetrics.MemStats.PauseNs = NewHistogram(NewExpDecaySample(1028, 0.015))
|
|
runtimeMetrics.MemStats.PauseNs = NewHistogram(NewExpDecaySample(1028, 0.015))
|
|
runtimeMetrics.MemStats.PauseTotalNs = NewGauge()
|
|
runtimeMetrics.MemStats.PauseTotalNs = NewGauge()
|
|
runtimeMetrics.MemStats.StackInuse = NewGauge()
|
|
runtimeMetrics.MemStats.StackInuse = NewGauge()
|
|
@@ -166,6 +175,7 @@ func RegisterRuntimeMemStats(r Registry) {
|
|
runtimeMetrics.MemStats.TotalAlloc = NewGauge()
|
|
runtimeMetrics.MemStats.TotalAlloc = NewGauge()
|
|
runtimeMetrics.NumCgoCall = NewGauge()
|
|
runtimeMetrics.NumCgoCall = NewGauge()
|
|
runtimeMetrics.NumGoroutine = NewGauge()
|
|
runtimeMetrics.NumGoroutine = NewGauge()
|
|
|
|
+ runtimeMetrics.NumThread = NewGauge()
|
|
runtimeMetrics.ReadMemStats = NewTimer()
|
|
runtimeMetrics.ReadMemStats = NewTimer()
|
|
|
|
|
|
r.Register("runtime.MemStats.Alloc", runtimeMetrics.MemStats.Alloc)
|
|
r.Register("runtime.MemStats.Alloc", runtimeMetrics.MemStats.Alloc)
|
|
@@ -188,6 +198,7 @@ func RegisterRuntimeMemStats(r Registry) {
|
|
r.Register("runtime.MemStats.MSpanSys", runtimeMetrics.MemStats.MSpanSys)
|
|
r.Register("runtime.MemStats.MSpanSys", runtimeMetrics.MemStats.MSpanSys)
|
|
r.Register("runtime.MemStats.NextGC", runtimeMetrics.MemStats.NextGC)
|
|
r.Register("runtime.MemStats.NextGC", runtimeMetrics.MemStats.NextGC)
|
|
r.Register("runtime.MemStats.NumGC", runtimeMetrics.MemStats.NumGC)
|
|
r.Register("runtime.MemStats.NumGC", runtimeMetrics.MemStats.NumGC)
|
|
|
|
+ r.Register("runtime.MemStats.GCCPUFraction", runtimeMetrics.MemStats.GCCPUFraction)
|
|
r.Register("runtime.MemStats.PauseNs", runtimeMetrics.MemStats.PauseNs)
|
|
r.Register("runtime.MemStats.PauseNs", runtimeMetrics.MemStats.PauseNs)
|
|
r.Register("runtime.MemStats.PauseTotalNs", runtimeMetrics.MemStats.PauseTotalNs)
|
|
r.Register("runtime.MemStats.PauseTotalNs", runtimeMetrics.MemStats.PauseTotalNs)
|
|
r.Register("runtime.MemStats.StackInuse", runtimeMetrics.MemStats.StackInuse)
|
|
r.Register("runtime.MemStats.StackInuse", runtimeMetrics.MemStats.StackInuse)
|
|
@@ -196,5 +207,6 @@ func RegisterRuntimeMemStats(r Registry) {
|
|
r.Register("runtime.MemStats.TotalAlloc", runtimeMetrics.MemStats.TotalAlloc)
|
|
r.Register("runtime.MemStats.TotalAlloc", runtimeMetrics.MemStats.TotalAlloc)
|
|
r.Register("runtime.NumCgoCall", runtimeMetrics.NumCgoCall)
|
|
r.Register("runtime.NumCgoCall", runtimeMetrics.NumCgoCall)
|
|
r.Register("runtime.NumGoroutine", runtimeMetrics.NumGoroutine)
|
|
r.Register("runtime.NumGoroutine", runtimeMetrics.NumGoroutine)
|
|
|
|
+ r.Register("runtime.NumThread", runtimeMetrics.NumThread)
|
|
r.Register("runtime.ReadMemStats", runtimeMetrics.ReadMemStats)
|
|
r.Register("runtime.ReadMemStats", runtimeMetrics.ReadMemStats)
|
|
}
|
|
}
|