Add go_gomaxprocs, go_gogc_percent and go_gomemlimit to the default Go runtime metrics
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
This commit is contained in:
parent
7cd1249dcc
commit
cd8445b70b
1
go.mod
1
go.mod
|
@ -18,6 +18,7 @@ require (
|
|||
|
||||
require (
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/hashicorp/go-version v1.7.0
|
||||
github.com/jpillora/backoff v1.0.0 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -14,6 +14,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
|
||||
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
|
|
|
@ -31,6 +31,9 @@ import (
|
|||
|
||||
var baseMetrics = []string{
|
||||
"go_gc_duration_seconds",
|
||||
"go_gogc_percent",
|
||||
"go_gomaxprocs",
|
||||
"go_gomemlimit",
|
||||
"go_goroutines",
|
||||
"go_info",
|
||||
"go_memstats_last_gc_time_seconds",
|
||||
|
|
|
@ -16,6 +16,7 @@ package prometheus
|
|||
import (
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
runmetr "runtime/metrics"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -211,6 +212,9 @@ type baseGoCollector struct {
|
|||
gcDesc *Desc
|
||||
gcLastTimeDesc *Desc
|
||||
goInfoDesc *Desc
|
||||
goMaxProcs *Desc
|
||||
goGogcPercent *Desc
|
||||
goMemLimit *Desc
|
||||
}
|
||||
|
||||
func newBaseGoCollector() baseGoCollector {
|
||||
|
@ -235,6 +239,18 @@ func newBaseGoCollector() baseGoCollector {
|
|||
"go_info",
|
||||
"Information about the Go environment.",
|
||||
nil, Labels{"version": runtime.Version()}),
|
||||
goMaxProcs: NewDesc(
|
||||
"go_gomaxprocs",
|
||||
"Value of GOMAXPROCS, i.e number of usable threads.",
|
||||
nil, nil),
|
||||
goGogcPercent: NewDesc(
|
||||
"go_gogc_percent",
|
||||
"Value of GOGC (percentage).",
|
||||
nil, nil),
|
||||
goMemLimit: NewDesc(
|
||||
"go_gomemlimit",
|
||||
"Value of GOMEMLIMIT (bytes).",
|
||||
nil, nil),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,6 +261,9 @@ func (c *baseGoCollector) Describe(ch chan<- *Desc) {
|
|||
ch <- c.gcDesc
|
||||
ch <- c.gcLastTimeDesc
|
||||
ch <- c.goInfoDesc
|
||||
ch <- c.goMaxProcs
|
||||
ch <- c.goGogcPercent
|
||||
ch <- c.goMemLimit
|
||||
}
|
||||
|
||||
// Collect returns the current state of all metrics of the collector.
|
||||
|
@ -266,6 +285,18 @@ func (c *baseGoCollector) Collect(ch chan<- Metric) {
|
|||
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), stats.PauseTotal.Seconds(), quantiles)
|
||||
ch <- MustNewConstMetric(c.gcLastTimeDesc, GaugeValue, float64(stats.LastGC.UnixNano())/1e9)
|
||||
ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1)
|
||||
ch <- MustNewConstMetric(c.goMaxProcs, GaugeValue, float64(runtime.NumCPU()))
|
||||
|
||||
gogcSample := make([]runmetr.Sample, 1)
|
||||
gogcSample[0].Name = "/gc/gogc:percent"
|
||||
runmetr.Read(gogcSample)
|
||||
ch <- MustNewConstMetric(c.goGogcPercent, GaugeValue, float64(gogcSample[0].Value.Uint64()))
|
||||
|
||||
memLimitSample := make([]runmetr.Sample, 1)
|
||||
memLimitSample[0].Name = "/gc/gomemlimit:bytes"
|
||||
runmetr.Read(memLimitSample)
|
||||
ch <- MustNewConstMetric(c.goMemLimit, GaugeValue, float64(memLimitSample[0].Value.Uint64()))
|
||||
|
||||
}
|
||||
|
||||
func memstatNamespace(s string) string {
|
||||
|
|
|
@ -54,6 +54,9 @@ func expectedBaseMetrics() map[string]struct{} {
|
|||
b.goroutinesDesc.fqName,
|
||||
b.gcLastTimeDesc.fqName,
|
||||
b.threadsDesc.fqName,
|
||||
b.goMaxProcs.fqName,
|
||||
b.goGogcPercent.fqName,
|
||||
b.goMemLimit.fqName,
|
||||
} {
|
||||
metrics[m] = struct{}{}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue