Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads #1559

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (

require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-version v1.7.0
bwplotka marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 3 additions & 0 deletions prometheus/collectors/go_collector_latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions prometheus/go_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package prometheus
import (
"runtime"
"runtime/debug"
runmetr "runtime/metrics"
"time"
)

Expand Down Expand Up @@ -211,6 +212,9 @@ type baseGoCollector struct {
gcDesc *Desc
gcLastTimeDesc *Desc
goInfoDesc *Desc
goMaxProcs *Desc
goGogcPercent *Desc
goMemLimit *Desc
}

func newBaseGoCollector() baseGoCollector {
Expand All @@ -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),
}
}

Expand All @@ -245,6 +261,9 @@ func (c *baseGoCollector) Describe(ch chan<- *Desc) {
ch <- c.gcDesc
ch <- c.gcLastTimeDesc
ch <- c.goInfoDesc
ch <- c.goMaxProcs
bwplotka marked this conversation as resolved.
Show resolved Hide resolved
ch <- c.goGogcPercent
ch <- c.goMemLimit
}

// Collect returns the current state of all metrics of the collector.
Expand All @@ -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)
bwplotka marked this conversation as resolved.
Show resolved Hide resolved
ch <- MustNewConstMetric(c.goGogcPercent, GaugeValue, float64(gogcSample[0].Value.Uint64()))

memLimitSample := make([]runmetr.Sample, 1)
memLimitSample[0].Name = "/gc/gomemlimit:bytes"
runmetr.Read(memLimitSample)
bwplotka marked this conversation as resolved.
Show resolved Hide resolved
ch <- MustNewConstMetric(c.goMemLimit, GaugeValue, float64(memLimitSample[0].Value.Uint64()))

}

func memstatNamespace(s string) string {
Expand Down
3 changes: 3 additions & 0 deletions prometheus/go_collector_latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
Expand Down
Loading