mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
cmd: expose an uptime metric for each command
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/reporter"
|
"akvorado/common/reporter"
|
||||||
@@ -22,6 +23,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
debug bool
|
debug bool
|
||||||
missedLogs atomic.Uint64
|
missedLogs atomic.Uint64
|
||||||
|
startTime time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
// RootCmd is the root for all commands
|
// RootCmd is the root for all commands
|
||||||
@@ -59,9 +61,16 @@ func moreMetrics(r *reporter.Reporter) {
|
|||||||
Help: "Akvorado build information",
|
Help: "Akvorado build information",
|
||||||
}, []string{"version", "compiler"}).
|
}, []string{"version", "compiler"}).
|
||||||
WithLabelValues(helpers.AkvoradoVersion, runtime.Version()).Set(1)
|
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() {
|
func init() {
|
||||||
|
startTime = time.Now()
|
||||||
RootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false,
|
RootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false,
|
||||||
"Enable debug logs")
|
"Enable debug logs")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user