From 57185f67dd87298ae305d7214730be39fba5fd17 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 19 Sep 2025 15:37:11 +0200 Subject: [PATCH] cmd: expose an uptime metric for each command --- cmd/root.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 4b513699..1c90c6c3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,7 @@ import ( "os" "runtime" "sync/atomic" + "time" "akvorado/common/helpers" "akvorado/common/reporter" @@ -22,6 +23,7 @@ import ( var ( debug bool missedLogs atomic.Uint64 + startTime time.Time ) // RootCmd is the root for all commands @@ -59,9 +61,16 @@ func moreMetrics(r *reporter.Reporter) { Help: "Akvorado build information", }, []string{"version", "compiler"}). WithLabelValues(helpers.AkvoradoVersion, runtime.Version()).Set(1) + r.GaugeFunc(reporter.GaugeOpts{ + Name: "uptime_seconds", + Help: "number of seconds the application is running", + }, func() float64 { + return time.Since(startTime).Seconds() + }) } func init() { + startTime = time.Now() RootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Enable debug logs") }