/
local_cache_stats.go
43 lines (39 loc) · 1.48 KB
/
local_cache_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package redis
import (
"github.com/coocood/freecache"
stats "github.com/lyft/gostats"
)
type localCacheStats struct {
cache *freecache.Cache
evacuateCount stats.Gauge
expiredCount stats.Gauge
entryCount stats.Gauge
averageAccessTime stats.Gauge
hitCount stats.Gauge
missCount stats.Gauge
lookupCount stats.Gauge
overwriteCount stats.Gauge
}
func NewLocalCacheStats(localCache *freecache.Cache, scope stats.Scope) stats.StatGenerator {
return localCacheStats{
cache: localCache,
evacuateCount: scope.NewGauge("evacuateCount"),
expiredCount: scope.NewGauge("expiredCount"),
entryCount: scope.NewGauge("entryCount"),
averageAccessTime: scope.NewGauge("averageAccessTime"),
hitCount: scope.NewGauge("hitCount"),
missCount: scope.NewGauge("missCount"),
lookupCount: scope.NewGauge("lookupCount"),
overwriteCount: scope.NewGauge("overwriteCount"),
}
}
func (stats localCacheStats) GenerateStats() {
stats.evacuateCount.Set(uint64(stats.cache.EvacuateCount()))
stats.expiredCount.Set(uint64(stats.cache.ExpiredCount()))
stats.entryCount.Set(uint64(stats.cache.EntryCount()))
stats.averageAccessTime.Set(uint64(stats.cache.AverageAccessTime()))
stats.hitCount.Set(uint64(stats.cache.HitCount()))
stats.missCount.Set(uint64(stats.cache.MissCount()))
stats.lookupCount.Set(uint64(stats.cache.LookupCount()))
stats.overwriteCount.Set(uint64(stats.cache.OverwriteCount()))
}