fix(backend): add a go_max_procs metric

This commit is contained in:
Łukasz Mierzwa
2021-06-03 14:19:14 +01:00
committed by Łukasz Mierzwa
parent 79c2fbc6e7
commit 186d2a4e01
3 changed files with 20 additions and 0 deletions

View File

@@ -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

View File

@@ -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() {

View File

@@ -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