@@ -7,6 +7,7 @@ package stats
77
88import (
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
4850func 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:
5685func (s * coreStats ) copyT (out copyTracker , diskLowUtil ... int64 ) bool {
5786 idle := true
0 commit comments