summary refs log tree commit diff
path: root/synapse/http/server.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-03-09 16:19:18 +0000
committerRichard van der Hoff <richard@matrix.org>2018-03-09 16:30:26 +0000
commit88541f9009a7ca39c85cac7483d6a240ef497d33 (patch)
tree20022955f62583d29277dbcd582dda93f8c1bae8 /synapse/http/server.py
parentrefactor JsonResource (diff)
downloadsynapse-88541f9009a7ca39c85cac7483d6a240ef497d33.tar.xz
Add a metric which increments when a request is received
It's useful to know when there are peaks in incoming requests - which isn't
quite the same as there being peaks in outgoing responses, due to the time
taken to handle requests.
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r--synapse/http/server.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index d774476e5b..6c5d8bb556 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -60,6 +60,11 @@ response_count = metrics.register_counter(
     )
 )
 
+requests_counter = metrics.register_counter(
+    "requests_received",
+    labels=["method", "servlet", ],
+)
+
 outgoing_responses_counter = metrics.register_counter(
     "responses",
     labels=["method", "code"],
@@ -146,7 +151,8 @@ def wrap_request_handler(request_handler, include_metrics=False):
                 # at the servlet name. For most requests that name will be
                 # JsonResource (or a subclass), and JsonResource._async_render
                 # will update it once it picks a servlet.
-                request_metrics.start(self.clock, name=self.__class__.__name__)
+                servlet_name = self.__class__.__name__
+                request_metrics.start(self.clock, name=servlet_name)
 
                 request_context.request = request_id
                 with request.processing():
@@ -155,6 +161,7 @@ def wrap_request_handler(request_handler, include_metrics=False):
                             if include_metrics:
                                 yield request_handler(self, request, request_metrics)
                             else:
+                                requests_counter.inc(request.method, servlet_name)
                                 yield request_handler(self, request)
                     except CodeMessageException as e:
                         code = e.code
@@ -286,6 +293,7 @@ class JsonResource(HttpServer, resource.Resource):
             servlet_classname = "%r" % callback
 
         request_metrics.name = servlet_classname
+        requests_counter.inc(request.method, servlet_classname)
 
         # Now trigger the callback. If it returns a response, we send it
         # here. If it throws an exception, that is handled by the wrapper
@@ -342,7 +350,7 @@ class JsonResource(HttpServer, resource.Resource):
 
 
 def _options_handler(request):
-    return {}
+    return 200, {}
 
 
 def _unrecognised_request_handler(request):