summary refs log tree commit diff
path: root/synapse/http/server.py
diff options
context:
space:
mode:
authorPaul Evans <leonerd@leonerd.org.uk>2015-03-13 17:31:10 +0000
committerPaul Evans <leonerd@leonerd.org.uk>2015-03-13 17:31:10 +0000
commite731d30d90680b98237aaff7e655f26e942f468c (patch)
treef04bf166aca228c53af3a1cb2d4626f4889cbf61 /synapse/http/server.py
parentAlso bump dependency link version (diff)
parentMerge remote-tracking branch 'origin/develop' into metrics (diff)
downloadsynapse-e731d30d90680b98237aaff7e655f26e942f468c.tar.xz
Merge pull request #108 from matrix-org/metrics
Metrics
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r--synapse/http/server.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 767c3ef79b..d77cb77799 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -18,6 +18,7 @@ from synapse.api.errors import (
     cs_exception, SynapseError, CodeMessageException, UnrecognizedRequestError
 )
 from synapse.util.logcontext import LoggingContext
+import synapse.metrics
 
 from syutil.jsonutil import (
     encode_canonical_json, encode_pretty_printed_json
@@ -34,6 +35,17 @@ import urllib
 
 logger = logging.getLogger(__name__)
 
+metrics = synapse.metrics.get_metrics_for(__name__)
+
+incoming_requests_counter = metrics.register_counter(
+    "requests",
+    labels=["method", "servlet"],
+)
+outgoing_responses_counter = metrics.register_counter(
+    "responses",
+    labels=["method", "code"],
+)
+
 
 class HttpServer(object):
     """ Interface for registering callbacks on a HTTP server
@@ -131,6 +143,15 @@ class JsonResource(HttpServer, resource.Resource):
                 # returned response. We pass both the request and any
                 # matched groups from the regex to the callback.
 
+                callback = path_entry.callback
+
+                servlet_instance = getattr(callback, "__self__", None)
+                if servlet_instance is not None:
+                    servlet_classname = servlet_instance.__class__.__name__
+                else:
+                    servlet_classname = "%r" % callback
+                incoming_requests_counter.inc(request.method, servlet_classname)
+
                 args = [
                     urllib.unquote(u).decode("UTF-8") for u in m.groups()
                 ]
@@ -140,10 +161,7 @@ class JsonResource(HttpServer, resource.Resource):
                     request.method, request.path
                 )
 
-                code, response = yield path_entry.callback(
-                    request,
-                    *args
-                )
+                code, response = yield callback(request, *args)
 
                 self._send_response(request, code, response)
                 return
@@ -190,6 +208,8 @@ class JsonResource(HttpServer, resource.Resource):
                 request)
             return
 
+        outgoing_responses_counter.inc(request.method, str(code))
+
         # TODO: Only enable CORS for the requests that need it.
         respond_with_json(
             request, code, response_json_object,