Skip to content

Commit 7e08a84

Browse files
committed
stats: register subset of go runtime metrics with prometheus
Signed-off-by: Aaron Wilson <aawilson@nvidia.com>
1 parent da541a1 commit 7e08a84

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

stats/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const (
3939

4040
// static labels
4141
const (
42-
ConstlabNode = "node_id"
42+
ConstlabNode = "node_id"
43+
ConstlabComponent = "component"
4344
)
4445

4546
// variable labels

stats/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ func (r *runner) RegExtMetric(snode *meta.Snode, name, kind string, extra *Extra
188188
func (r *runner) regCommon(snode *meta.Snode) {
189189
initProm(snode)
190190

191+
regGoRuntime(snode.Type())
192+
191193
// basic counters
192194
r.reg(snode, GetCount, KindCounter,
193195
&Extra{

stats/common_prom.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package stats
77

88
import (
99
"net/http"
10+
"regexp"
1011
"strings"
1112
ratomic "sync/atomic"
1213
"time"
@@ -16,6 +17,7 @@ import (
1617
"github.com/NVIDIA/aistore/memsys"
1718

1819
"github.com/prometheus/client_golang/prometheus"
20+
"github.com/prometheus/client_golang/prometheus/collectors"
1921
"github.com/prometheus/client_golang/prometheus/promhttp"
2022
)
2123

@@ -46,12 +48,39 @@ var (
4648
)
4749

4850
func initProm(snode *meta.Snode) {
49-
// devoid of _default_ metrics go_gc*, go_mem*, and such
5051
promRegistry = prometheus.NewRegistry()
5152

5253
staticLabs[ConstlabNode] = strings.ReplaceAll(snode.ID(), ".", "_")
5354
}
5455

56+
// Expose a low-cardinality subset of Go runtime metrics on the AIS Prometheus registry:
57+
// - base collector (unconditional):
58+
// go_goroutines, go_threads, go_info, go_gc_duration_seconds, go_memstats_last_gc_time_seconds
59+
// - default runtime/metrics matcher:
60+
// go_gc_gogc_percent, go_gc_gomemlimit_bytes, go_sched_gomaxprocs_threads
61+
// - explicit picks via WithGoCollectorRuntimeMetrics below (one series each)
62+
func regGoRuntime(daeType string) {
63+
nodeLabs := prometheus.Labels{
64+
ConstlabNode: staticLabs[ConstlabNode],
65+
ConstlabComponent: daeType,
66+
}
67+
reg := prometheus.WrapRegistererWith(nodeLabs, promRegistry)
68+
reg.MustRegister(collectors.NewGoCollector(
69+
// skip legacy go_memstats_* block (21 series, mostly duplicative); use runtime/metrics names instead
70+
collectors.WithGoCollectorMemStatsMetricsDisabled(),
71+
collectors.WithGoCollectorRuntimeMetrics(
72+
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile(
73+
`^/memory/classes/heap/objects:bytes$` + // heap in use
74+
`|^/memory/classes/total:bytes$` + // total from OS
75+
`|^/gc/heap/goal:bytes$` + // next GC target
76+
`|^/gc/heap/allocs:bytes$` + // cumulative alloc bytes (counter)
77+
`|^/cpu/classes/gc/total:cpu-seconds$` + // cumulative GC CPU time
78+
`|^/gc/cycles/total:gc-cycles$`, // cumulative GC cycle count
79+
)},
80+
),
81+
))
82+
}
83+
5584
// usage: log resulting `copyValue` numbers:
5685
func (s *coreStats) copyT(out copyTracker, diskLowUtil ...int64) bool {
5786
idle := true

0 commit comments

Comments
 (0)