diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2021-01-13 17:31:46 +0000 |
---|---|---|
committer | Neil Alexander <neilalexander@users.noreply.github.com> | 2021-01-13 17:31:46 +0000 |
commit | 3ac693c7a5fcaff216b866be477517fa1b22cf3a (patch) | |
tree | 9bad7c2d7d9619becf87e8a3da46b34e78dbffdd /roomserver | |
parent | 266f9c4abdd6441f66e3e49809f10d11a6f221f7 (diff) |
Add dendrite_roomserver_processroomevent_duration_millis to prometheus
Squashed commit of the following:
commit e5e2d793119733ecbcf9b85f966e018ab0318741
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Wed Jan 13 17:28:12 2021 +0000
Add dendrite_roomserver_processroomevent_duration_millis to prometheus
Diffstat (limited to 'roomserver')
-rw-r--r-- | roomserver/internal/input/input_events.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go index d62621c2..2a558c48 100644 --- a/roomserver/internal/input/input_events.go +++ b/roomserver/internal/input/input_events.go @@ -20,6 +20,7 @@ import ( "bytes" "context" "fmt" + "time" "github.com/matrix-org/dendrite/internal/eventutil" "github.com/matrix-org/dendrite/roomserver/api" @@ -28,9 +29,29 @@ import ( "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" + "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" ) +func init() { + prometheus.MustRegister(processRoomEventDuration) +} + +var processRoomEventDuration = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Namespace: "dendrite", + Subsystem: "roomserver", + Name: "processroomevent_duration_millis", + Help: "How long it takes the roomserver to process an event", + Buckets: []float64{ // milliseconds + 5, 10, 25, 50, 75, 100, 250, 500, + 1000, 2000, 3000, 4000, 5000, 6000, + 7000, 8000, 9000, 10000, 15000, 20000, + }, + }, + []string{"room_id"}, +) + // processRoomEvent can only be called once at a time // // TODO(#375): This should be rewritten to allow concurrent calls. The @@ -42,6 +63,15 @@ func (r *Inputer) processRoomEvent( ctx context.Context, input *api.InputRoomEvent, ) (eventID string, err error) { + // Measure how long it takes to process this event. + started := time.Now() + defer func() { + timetaken := time.Since(started) + processRoomEventDuration.With(prometheus.Labels{ + "room_id": input.Event.RoomID(), + }).Observe(float64(timetaken.Milliseconds())) + }() + // Parse and validate the event JSON headered := input.Event event := headered.Unwrap() |