Report info metric as 0 the first time to track when software is (re)started

This commit is contained in:
Daniel 2023-10-12 17:11:00 +02:00
parent 05bdc44611
commit 7799e85d7a

View file

@ -3,10 +3,13 @@ package metrics
import (
"runtime"
"strings"
"sync/atomic"
"github.com/safing/portbase/info"
)
var reportedStart atomic.Bool
func registerInfoMetric() error {
meta := info.GetInfo()
_, err := NewGauge(
@ -26,6 +29,10 @@ func registerInfoMetric() error {
"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,