mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-23 00:21:53 +02:00
feat(metrics): add cache, process and http metrics
This commit is contained in:
Vendored
+22
@@ -9,11 +9,33 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
||||
_ "gitea.com/go-chi/cache/memcache" //nolint:depguard // memcache plugin for cache, it is required for config "ADAPTER=memcache"
|
||||
)
|
||||
|
||||
var defaultCache StringCache
|
||||
var hitCounter = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "gitea",
|
||||
Help: "Cache hit count",
|
||||
Subsystem: "cache",
|
||||
Name: "hit",
|
||||
})
|
||||
var missCounter = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "gitea",
|
||||
Help: "Cache miss count",
|
||||
Subsystem: "cache",
|
||||
Name: "miss",
|
||||
})
|
||||
var latencyHistogram = promauto.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: "gitea",
|
||||
Help: "Cache latency",
|
||||
Subsystem: "cache",
|
||||
Name: "duration",
|
||||
},
|
||||
)
|
||||
|
||||
// Init start cache service
|
||||
func Init() error {
|
||||
|
||||
Vendored
+6
@@ -6,6 +6,7 @@ package cache
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -63,10 +64,15 @@ func (sc *stringCache) Ping() error {
|
||||
}
|
||||
|
||||
func (sc *stringCache) Get(key string) (string, bool) {
|
||||
start := time.Now()
|
||||
v := sc.chiCache.Get(key)
|
||||
elapsed := time.Since(start).Seconds()
|
||||
latencyHistogram.Observe(elapsed)
|
||||
if v == nil {
|
||||
missCounter.Add(1)
|
||||
return "", false
|
||||
}
|
||||
hitCounter.Add(1)
|
||||
s, ok := v.(string)
|
||||
return s, ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user