forked from mirror/client_golang
use counters where applicable, improve descriptions
This commit is contained in:
parent
8a6e3ecf23
commit
b14b149930
|
@ -9,9 +9,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type goCollector struct {
|
type goCollector struct {
|
||||||
*memStatsCollector
|
|
||||||
goroutines Gauge
|
goroutines Gauge
|
||||||
gcDesc *Desc
|
gcDesc *Desc
|
||||||
|
alloc prometheus.Gauge
|
||||||
|
totalAlloc prometheus.Gauge
|
||||||
|
sys prometheus.Gauge
|
||||||
|
lookups prometheus.Gauge
|
||||||
|
mallocs prometheus.Gauge
|
||||||
|
frees prometheus.Gauge
|
||||||
|
heapAlloc prometheus.Gauge
|
||||||
|
heapSys prometheus.Gauge
|
||||||
|
heapIdle prometheus.Gauge
|
||||||
|
heapInuse prometheus.Gauge
|
||||||
|
heapReleased prometheus.Gauge
|
||||||
|
heapObjects prometheus.Gauge
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGoCollector returns a collector which exports metrics about the current
|
// NewGoCollector returns a collector which exports metrics about the current
|
||||||
|
@ -26,7 +37,78 @@ func NewGoCollector() *goCollector {
|
||||||
"go_gc_duration_seconds",
|
"go_gc_duration_seconds",
|
||||||
"A summary of the GC invocation durations.",
|
"A summary of the GC invocation durations.",
|
||||||
nil, nil),
|
nil, nil),
|
||||||
memStatsCollector: newMemStatsCollector(),
|
alloc: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "alloc_bytes",
|
||||||
|
Help: "Number of bytes allocated and still in use.",
|
||||||
|
}),
|
||||||
|
totalAlloc: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "alloc_bytes_total",
|
||||||
|
Help: "Total number of bytes allocated, even if freed.",
|
||||||
|
}),
|
||||||
|
sys: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "sys_bytes",
|
||||||
|
Help: "Number of bytes obtained from system",
|
||||||
|
}),
|
||||||
|
lookups: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "lookups_total",
|
||||||
|
Help: "Total number of pointer lookups.",
|
||||||
|
}),
|
||||||
|
mallocs: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "mallocs_total",
|
||||||
|
Help: "Total number of mallocs.",
|
||||||
|
}),
|
||||||
|
frees: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "frees_total",
|
||||||
|
Help: "Total number of frees.",
|
||||||
|
}),
|
||||||
|
heapAlloc: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "heap_alloc_bytes",
|
||||||
|
Help: "Number heap bytes allocated and still in use.",
|
||||||
|
}),
|
||||||
|
heapSys: prometheus.NewCounter(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "heap_sys_bytes",
|
||||||
|
Help: "Total bytes in heap obtained from system.",
|
||||||
|
}),
|
||||||
|
heapIdle: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "heap_idle_bytes",
|
||||||
|
Help: "Number bytes in heap waiting to be used.",
|
||||||
|
}),
|
||||||
|
heapInuse: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "heap_inuse_bytes",
|
||||||
|
Help: "Number of bytes in heap that are in use.",
|
||||||
|
}),
|
||||||
|
heapReleased: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "heap_released_bytes",
|
||||||
|
Help: "Number of bytes in heap released to OS.",
|
||||||
|
}),
|
||||||
|
heapObjects: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "go",
|
||||||
|
Subsystem: "memstats",
|
||||||
|
Name: "heap_objects",
|
||||||
|
Help: "Number of allocated objects.",
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +116,18 @@ func NewGoCollector() *goCollector {
|
||||||
func (c *goCollector) Describe(ch chan<- *Desc) {
|
func (c *goCollector) Describe(ch chan<- *Desc) {
|
||||||
ch <- c.goroutines.Desc()
|
ch <- c.goroutines.Desc()
|
||||||
ch <- c.gcDesc
|
ch <- c.gcDesc
|
||||||
|
ch <- m.alloc.Desc()
|
||||||
|
ch <- m.totalAlloc.Desc()
|
||||||
|
ch <- m.sys.Desc()
|
||||||
|
ch <- m.lookups.Desc()
|
||||||
|
ch <- m.mallocs.Desc()
|
||||||
|
ch <- m.frees.Desc()
|
||||||
|
ch <- m.heapAlloc.Desc()
|
||||||
|
ch <- m.heapSys.Desc()
|
||||||
|
ch <- m.heapIdle.Desc()
|
||||||
|
ch <- m.heapInuse.Desc()
|
||||||
|
ch <- m.heapReleased.Desc()
|
||||||
|
ch <- m.heapObjects.Desc()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect returns the current state of all metrics of the collector.
|
// Collect returns the current state of all metrics of the collector.
|
||||||
|
@ -51,128 +145,6 @@ func (c *goCollector) Collect(ch chan<- Metric) {
|
||||||
}
|
}
|
||||||
quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
|
quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
|
||||||
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles)
|
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles)
|
||||||
}
|
|
||||||
|
|
||||||
// memStatsCollector collects runtime.MemStats
|
|
||||||
type memStatsCollector struct {
|
|
||||||
alloc prometheus.Gauge
|
|
||||||
totalAlloc prometheus.Gauge
|
|
||||||
sys prometheus.Gauge
|
|
||||||
lookups prometheus.Gauge
|
|
||||||
mallocs prometheus.Gauge
|
|
||||||
frees prometheus.Gauge
|
|
||||||
heapAlloc prometheus.Gauge
|
|
||||||
heapSys prometheus.Gauge
|
|
||||||
heapIdle prometheus.Gauge
|
|
||||||
heapInuse prometheus.Gauge
|
|
||||||
heapReleased prometheus.Gauge
|
|
||||||
heapObjects prometheus.Gauge
|
|
||||||
}
|
|
||||||
|
|
||||||
// newMemStatsCollector creates a new runtime.MemStats collector
|
|
||||||
func newMemStatsCollector() *memStatsCollector {
|
|
||||||
return &MemStatsCollector{
|
|
||||||
alloc: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "alloc_bytes",
|
|
||||||
Help: "bytes allocated and still in use",
|
|
||||||
}),
|
|
||||||
totalAlloc: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "alloc_bytes_total",
|
|
||||||
Help: "bytes allocated (even if freed)",
|
|
||||||
}),
|
|
||||||
sys: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "sys",
|
|
||||||
Help: "bytes obtained from system",
|
|
||||||
}),
|
|
||||||
lookups: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "lookups",
|
|
||||||
Help: "number of pointer lookups",
|
|
||||||
}),
|
|
||||||
mallocs: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "mallocs",
|
|
||||||
Help: "number of mallocs",
|
|
||||||
}),
|
|
||||||
frees: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "frees",
|
|
||||||
Help: "number of frees",
|
|
||||||
}),
|
|
||||||
heapAlloc: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "heap_alloc",
|
|
||||||
Help: "bytes allocated and still in use",
|
|
||||||
}),
|
|
||||||
heapSys: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "heap_sys",
|
|
||||||
Help: "bytes obtained from system",
|
|
||||||
}),
|
|
||||||
heapIdle: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "heap_idle",
|
|
||||||
Help: "bytes in idle spans",
|
|
||||||
}),
|
|
||||||
heapInuse: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "heap_inuse",
|
|
||||||
Help: "bytes in non-idle span",
|
|
||||||
}),
|
|
||||||
heapReleased: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "heap_released",
|
|
||||||
Help: "bytes released to the OS",
|
|
||||||
}),
|
|
||||||
heapObjects: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Namespace: "go",
|
|
||||||
Subsystem: "memstats",
|
|
||||||
Name: "heap_objects",
|
|
||||||
Help: "total number of allocated objects",
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Describe sends Desc objects for each memstat we intend to collect.
|
|
||||||
func (m *MemStatsCollector) Describe(ch chan<- *prometheus.Desc) {
|
|
||||||
if m == nil {
|
|
||||||
m = NewMemStatsCollector()
|
|
||||||
}
|
|
||||||
|
|
||||||
ch <- m.alloc.Desc()
|
|
||||||
ch <- m.totalAlloc.Desc()
|
|
||||||
ch <- m.sys.Desc()
|
|
||||||
ch <- m.lookups.Desc()
|
|
||||||
ch <- m.mallocs.Desc()
|
|
||||||
ch <- m.frees.Desc()
|
|
||||||
ch <- m.heapAlloc.Desc()
|
|
||||||
ch <- m.heapSys.Desc()
|
|
||||||
ch <- m.heapIdle.Desc()
|
|
||||||
ch <- m.heapInuse.Desc()
|
|
||||||
ch <- m.heapReleased.Desc()
|
|
||||||
ch <- m.heapObjects.Desc()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect does the trick by calling ReadMemStats once and then constructing
|
|
||||||
// three different Metrics on the fly.
|
|
||||||
func (m *MemStatsCollector) Collect(ch chan<- prometheus.Metric) {
|
|
||||||
if m == nil {
|
|
||||||
m = NewMemStatsCollector()
|
|
||||||
}
|
|
||||||
|
|
||||||
var ms runtime.MemStats
|
var ms runtime.MemStats
|
||||||
runtime.ReadMemStats(&ms)
|
runtime.ReadMemStats(&ms)
|
||||||
|
|
Loading…
Reference in New Issue