forked from vikunja/vikunja
fix(metrics): make currently active users actually work
This commit is contained in:
parent
a9e6776abf
commit
811514855b
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user