diff --git a/pkg/metrics/active_users.go b/pkg/metrics/active_users.go index deeddc3340..f833e2c441 100644 --- a/pkg/metrics/active_users.go +++ b/pkg/metrics/active_users.go @@ -28,7 +28,7 @@ import ( ) // SecondsUntilInactive defines the seconds until a user is considered inactive -const SecondsUntilInactive = 60 +const SecondsUntilInactive = 30 // ActiveUsersKey is the key used to store active users in redis const ActiveUsersKey = `activeusers` @@ -55,12 +55,13 @@ func init() { users: make(map[int64]*ActiveUser), mutex: &sync.Mutex{}, } +} - promauto.NewGaugeFunc(prometheus.GaugeOpts{ +func setupActiveUsersMetric() { + err := registry.Register(promauto.NewGaugeFunc(prometheus.GaugeOpts{ Name: "vikunja_active_users", - Help: "The currently active users on this node", + Help: "The number of users active within the last 30 seconds on this node", }, func() float64 { - allActiveUsers, err := getActiveUsers() if err != nil { log.Error(err.Error()) @@ -75,7 +76,10 @@ func init() { } } return float64(activeUsersCount) - }) + })) + if err != nil { + log.Criticalf("Could not register metrics for currently active users: %s", err) + } } // SetUserActive sets a user as active and pushes it to redis diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 4e6a7e8631..68dafc913c 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -113,7 +113,7 @@ func InitMetrics() { log.Criticalf("Could not register metrics for %s: %s", TaskCountKey, err) } - // Register total user count metric + // Register total teams count metric err = registry.Register(promauto.NewGaugeFunc(prometheus.GaugeOpts{ Name: "vikunja_team_count", Help: "The total number of teams on this instance", @@ -124,9 +124,11 @@ func InitMetrics() { if err != nil { log.Criticalf("Could not register metrics for %s: %s", TeamCountKey, err) } + + setupActiveUsersMetric() } -// GetCount returns the current count from redis +// GetCount returns the current count from keyvalue func GetCount(key string) (count int64, err error) { cnt, exists, err := keyvalue.Get(key) if err != nil {