Cache total stats in memory
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.uio.no/torjus/apiary/models"
|
||||
)
|
||||
@@ -17,7 +14,7 @@ type MetricsCollectingStore struct {
|
||||
totalAttemptsCount prometheus.Gauge
|
||||
}
|
||||
|
||||
func NewMetricsCollectingStore(ctx context.Context, store LoginAttemptStore) *MetricsCollectingStore {
|
||||
func NewMetricsCollectingStore(store LoginAttemptStore) *MetricsCollectingStore {
|
||||
mcs := &MetricsCollectingStore{store: store}
|
||||
|
||||
mcs.attemptsCounter = prometheus.NewCounterVec(
|
||||
@@ -62,17 +59,6 @@ func NewMetricsCollectingStore(ctx context.Context, store LoginAttemptStore) *Me
|
||||
prometheus.MustRegister(mcs.uniqueIPsCount)
|
||||
prometheus.MustRegister(mcs.totalAttemptsCount)
|
||||
|
||||
// Kinda jank, we just fetch the stats every 10seconds, but it should be cached most of the time.
|
||||
go func(ctx context.Context) {
|
||||
ticker := time.NewTicker(10 * time.Second)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
mcs.Stats(LoginStatsTotals, 0)
|
||||
}
|
||||
}(ctx)
|
||||
|
||||
return mcs
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user