mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-13 23:31:34 +00:00
Prometheus metrics for LRU cache (#1039)
* Add prom metrics for the in-memory LRU cache * Increase cache sizes
This commit is contained in:
parent
2b5052eccf
commit
f0e0a6668f
@ -1,10 +1,12 @@
|
|||||||
package caching
|
package caching
|
||||||
|
|
||||||
import "github.com/matrix-org/gomatrixserverlib"
|
import (
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RoomVersionMaxCacheEntries = 128
|
RoomVersionMaxCacheEntries = 1024
|
||||||
ServerKeysMaxCacheEntries = 128
|
ServerKeysMaxCacheEntries = 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImmutableCache interface {
|
type ImmutableCache interface {
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImmutableInMemoryLRUCache struct {
|
type ImmutableInMemoryLRUCache struct {
|
||||||
@ -21,10 +23,32 @@ func NewImmutableInMemoryLRUCache() (*ImmutableInMemoryLRUCache, error) {
|
|||||||
if rvErr != nil {
|
if rvErr != nil {
|
||||||
return nil, rvErr
|
return nil, rvErr
|
||||||
}
|
}
|
||||||
return &ImmutableInMemoryLRUCache{
|
cache := &ImmutableInMemoryLRUCache{
|
||||||
roomVersions: roomVersionCache,
|
roomVersions: roomVersionCache,
|
||||||
serverKeys: serverKeysCache,
|
serverKeys: serverKeysCache,
|
||||||
}, nil
|
}
|
||||||
|
cache.configureMetrics()
|
||||||
|
return cache, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ImmutableInMemoryLRUCache) configureMetrics() {
|
||||||
|
promauto.NewGaugeFunc(prometheus.GaugeOpts{
|
||||||
|
Namespace: "dendrite",
|
||||||
|
Subsystem: "caching",
|
||||||
|
Name: "number_room_version_entries",
|
||||||
|
Help: "The number of room version entries cached.",
|
||||||
|
}, func() float64 {
|
||||||
|
return float64(c.roomVersions.Len())
|
||||||
|
})
|
||||||
|
|
||||||
|
promauto.NewGaugeFunc(prometheus.GaugeOpts{
|
||||||
|
Namespace: "dendrite",
|
||||||
|
Subsystem: "caching",
|
||||||
|
Name: "number_server_key_entries",
|
||||||
|
Help: "The number of server key entries cached.",
|
||||||
|
}, func() float64 {
|
||||||
|
return float64(c.serverKeys.Len())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkForInvalidMutation(cache *lru.Cache, key string, value interface{}) {
|
func checkForInvalidMutation(cache *lru.Cache, key string, value interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user