diff --git a/CHANGELOG.md b/CHANGELOG.md index d9f70e1d0..32fb5fd3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Use [uber-go/automaxprocs](https://github.com/uber-go/automaxprocs) to automatically adjust `GOMAXPROCS` to match Linux container CPU quota. + Runtime value of `GOMAXPROCS` is now exported as a `go_max_procs` metric. ## v0.86 diff --git a/cmd/karma/metrics.go b/cmd/karma/metrics.go index 9f299f5da..9958a6717 100644 --- a/cmd/karma/metrics.go +++ b/cmd/karma/metrics.go @@ -1,6 +1,8 @@ package main import ( + "runtime" + "github.com/prometheus/client_golang/prometheus" "github.com/prymitive/karma/internal/alertmanager" ) @@ -11,6 +13,7 @@ type karmaCollector struct { cyclesTotal *prometheus.Desc errorsTotal *prometheus.Desc alertmanagerUp *prometheus.Desc + goMaxProcs *prometheus.Desc } func newKarmaCollector() *karmaCollector { @@ -45,6 +48,12 @@ func newKarmaCollector() *karmaCollector { []string{"alertmanager"}, prometheus.Labels{}, ), + goMaxProcs: prometheus.NewDesc( + "go_max_procs", + "Value of the GOMAXPROCS setting", + []string{}, + prometheus.Labels{}, + ), } } @@ -54,6 +63,7 @@ func (c *karmaCollector) Describe(ch chan<- *prometheus.Desc) { ch <- c.cyclesTotal ch <- c.errorsTotal ch <- c.alertmanagerUp + ch <- c.goMaxProcs } func (c *karmaCollector) Collect(ch chan<- prometheus.Metric) { @@ -133,6 +143,12 @@ func (c *karmaCollector) Collect(ch chan<- prometheus.Metric) { am.Name, ) } + + ch <- prometheus.MustNewConstMetric( + c.goMaxProcs, + prometheus.GaugeValue, + float64(runtime.GOMAXPROCS(0)), + ) } func init() { diff --git a/cmd/karma/tests/testscript/083_metrics.txt b/cmd/karma/tests/testscript/083_metrics.txt index fe739cfe3..5d6753b56 100644 --- a/cmd/karma/tests/testscript/083_metrics.txt +++ b/cmd/karma/tests/testscript/083_metrics.txt @@ -19,6 +19,9 @@ go_gc_duration_seconds_count # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge go_goroutines +# HELP go_max_procs Value of the GOMAXPROCS setting +# TYPE go_max_procs gauge +go_max_procs # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use. # TYPE go_memstats_alloc_bytes gauge go_memstats_alloc_bytes