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 ( import (
"runtime" "runtime"
"strings" "strings"
"sync/atomic"
"github.com/safing/portbase/info" "github.com/safing/portbase/info"
) )
var reportedStart atomic.Bool
func registerInfoMetric() error { func registerInfoMetric() error {
meta := info.GetInfo() meta := info.GetInfo()
_, err := NewGauge( _, err := NewGauge(
@ -26,6 +29,10 @@ func registerInfoMetric() error {
"comment": commentOption(), "comment": commentOption(),
}, },
func() float64 { func() float64 {
// Report as 0 the first time in order to detect (re)starts.
if reportedStart.CompareAndSwap(false, true) {
return 0
}
return 1 return 1
}, },
nil, nil,