Add event/update counter to metrics

This commit is contained in:
Tulir Asokan
2019-06-01 21:10:01 +03:00
parent a279835cf8
commit 145eb8f611
2 changed files with 15 additions and 5 deletions
+7 -2
View File
@@ -29,13 +29,17 @@ if TYPE_CHECKING:
from .context import Context
try:
from prometheus_client import Histogram
from prometheus_client import Histogram, Counter
EVENT_COUNT = Counter("matrix_event_count", "Number of Matrix events processed",
["event_type"])
EVENT_TIME = Histogram("matrix_event", "Time spent processing Matrix events",
["event_type"])
except ImportError:
Histogram = None
EVENT_TIME = None
EVENT_COUNT = None
class MatrixHandler:
log = logging.getLogger("mau.mx") # type: logging.Logger
@@ -442,5 +446,6 @@ class MatrixHandler:
await self.handle_typing(room_id, content.get("user_ids", []))
else:
return
if EVENT_TIME:
if EVENT_TIME and EVENT_COUNT:
EVENT_TIME.labels(event_type=evt_type).observe(time.time() - start_time)
EVENT_COUNT.labels(event_type=evt_type).inc()