Skip to content

Commit

Permalink
Change Redis metrics from Gauge to Counter
Browse files Browse the repository at this point in the history
Updated Redis connection metrics (hits, misses, timeouts) from Gauge to Counter to ensure accurate cumulative counts. Modified the update logic to use Add instead of Set for handling differences in metric values. Adjusted the ticker interval to collect metrics every 10 seconds instead of 1 minute.

Signed-off-by: Christian Roessner <[email protected]>
  • Loading branch information
Christian Roessner committed Nov 8, 2024
1 parent 6a6f030 commit 6042ff3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions server/core/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func UpdateRedisPoolStats() {
previousHits := make(map[string]float64)
previousMisses := make(map[string]float64)
previousTimeouts := make(map[string]float64)
ticker := time.NewTicker(time.Minute)
ticker := time.NewTicker(time.Second * 10)

defer ticker.Stop()

Expand Down Expand Up @@ -151,21 +151,21 @@ func UpdateRedisPoolStats() {
if previousHit, ok := previousHits[poolName]; ok {
hitsDiff := currentHits - previousHit
if hitsDiff >= 0 {
stats.RedisHits.With(prometheus.Labels{global.ReisPromPoolName: poolName}).Set(hitsDiff)
stats.RedisHits.With(prometheus.Labels{global.ReisPromPoolName: poolName}).Add(hitsDiff)
}
}

if previousMiss, ok := previousMisses[poolName]; ok {
missesDiff := currentMisses - previousMiss
if missesDiff >= 0 {
stats.RedisMisses.With(prometheus.Labels{global.ReisPromPoolName: poolName}).Set(missesDiff)
stats.RedisMisses.With(prometheus.Labels{global.ReisPromPoolName: poolName}).Add(missesDiff)
}
}

if previousTimeout, ok := previousTimeouts[poolName]; ok {
timeoutsDiff := currentTimeouts - previousTimeout
if timeoutsDiff >= 0 {
stats.RedisTimeouts.With(prometheus.Labels{global.ReisPromPoolName: poolName}).Set(timeoutsDiff)
stats.RedisTimeouts.With(prometheus.Labels{global.ReisPromPoolName: poolName}).Add(timeoutsDiff)
}
}

Expand Down
6 changes: 3 additions & 3 deletions server/stats/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ var (
})

// RedisHits gauges the total number of times a free connection was found in the pool, categorized by type.
RedisHits = promauto.NewGaugeVec(prometheus.GaugeOpts{
RedisHits = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "redis_connection_hits_total",
Help: "The total number of times a free connection was found in the pool",
}, []string{global.ReisPromPoolName})

// RedisMisses is a gauge vector that counts the total number of times a free connection was NOT found in the pool.
RedisMisses = promauto.NewGaugeVec(prometheus.GaugeOpts{
RedisMisses = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "redis_connection_misses_total",
Help: "The total number of times a free connection was NOT found in the pool",
}, []string{global.ReisPromPoolName})

// RedisTimeouts tracks the total number of times a wait timeout occurred in Redis connections.
RedisTimeouts = promauto.NewGaugeVec(prometheus.GaugeOpts{
RedisTimeouts = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "redis_connection_timeouts_total",
Help: "The total number of times a wait timeout occurred",
}, []string{global.ReisPromPoolName})
Expand Down

0 comments on commit 6042ff3

Please sign in to comment.