github.com/safing/portbase@v0.19.5/metrics/metrics_info.go (about) 1 package metrics 2 3 import ( 4 "runtime" 5 "strings" 6 "sync/atomic" 7 8 "github.com/safing/portbase/info" 9 ) 10 11 var reportedStart atomic.Bool 12 13 func registerInfoMetric() error { 14 meta := info.GetInfo() 15 _, err := NewGauge( 16 "info", 17 map[string]string{ 18 "version": checkUnknown(meta.Version), 19 "commit": checkUnknown(meta.Commit), 20 "build_date": checkUnknown(meta.BuildTime), 21 "build_source": checkUnknown(meta.Source), 22 "go_os": runtime.GOOS, 23 "go_arch": runtime.GOARCH, 24 "go_version": runtime.Version(), 25 "go_compiler": runtime.Compiler, 26 "comment": commentOption(), 27 }, 28 func() float64 { 29 // Report as 0 the first time in order to detect (re)starts. 30 if reportedStart.CompareAndSwap(false, true) { 31 return 0 32 } 33 return 1 34 }, 35 nil, 36 ) 37 return err 38 } 39 40 func checkUnknown(s string) string { 41 if strings.Contains(s, "unknown") { 42 return "unknown" 43 } 44 return s 45 }