Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add some metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jan 21, 2021
1 parent 62857fb commit 007c326
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions synapse/replication/tcp/external_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@
import logging
from typing import TYPE_CHECKING, Any, Optional

from prometheus_client import Counter

from synapse.util import json_decoder, json_encoder

if TYPE_CHECKING:
from synapse.server import HomeServer

set_counter = Counter(
"synapse_external_cache_set",
"Number of times we set a cache",
labelnames=["cache_name"],
)

get_counter = Counter(
"synapse_external_cache_get",
"Number of times we get a cache",
labelnames=["cache_name", "hit"],
)


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,6 +77,8 @@ async def set_cache(
if self._redis_connection is None:
return

set_counter.labels(cache_name).inc()

# txredisapi requires the value to be string, bytes or numbers, so we
# encode stuff in JSON.
encoded_value = json_encoder.encode(value)
Expand All @@ -84,6 +100,8 @@ async def get_cache(self, cache_name: str, key: str) -> Optional[Any]:

logger.debug("Got cache result %s %s: %r", cache_name, key, result)

get_counter.labels(cache_name, result is not None).inc()

if not result:
return None

Expand Down

0 comments on commit 007c326

Please sign in to comment.