mirror of
https://github.com/safing/portbase
synced 2025-04-22 02:09:09 +00:00
45 lines
916 B
Go
45 lines
916 B
Go
package metrics
|
|
|
|
import (
|
|
"runtime"
|
|
"strings"
|
|
"sync/atomic"
|
|
|
|
"github.com/safing/portbase/info"
|
|
)
|
|
|
|
var reportedStart atomic.Bool
|
|
|
|
func registerInfoMetric() error {
|
|
meta := info.GetInfo()
|
|
_, err := NewGauge(
|
|
"info",
|
|
map[string]string{
|
|
"version": checkUnknown(meta.Version),
|
|
"commit": checkUnknown(meta.Commit),
|
|
"build_date": checkUnknown(meta.BuildTime),
|
|
"build_source": checkUnknown(meta.Source),
|
|
"go_os": runtime.GOOS,
|
|
"go_arch": runtime.GOARCH,
|
|
"go_version": runtime.Version(),
|
|
"go_compiler": runtime.Compiler,
|
|
"comment": commentOption(),
|
|
},
|
|
func() float64 {
|
|
// Report as 0 the first time in order to detect (re)starts.
|
|
if reportedStart.CompareAndSwap(false, true) {
|
|
return 0
|
|
}
|
|
return 1
|
|
},
|
|
nil,
|
|
)
|
|
return err
|
|
}
|
|
|
|
func checkUnknown(s string) string {
|
|
if strings.Contains(s, "unknown") {
|
|
return "unknown"
|
|
}
|
|
return s
|
|
}
|