summary refs log tree commit diff
path: root/synapse/http/client.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-02-24 19:51:21 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:50 +0000
commit7d72e44eb9660eaeab017897853cf3ec18fd06c6 (patch)
tree78c1e01961ab8e8ff36a4def621b7b6f1a3e136b /synapse/http/client.py
parentPull out all uses of the underlying HTTP user agent .request() method into a ... (diff)
downloadsynapse-7d72e44eb9660eaeab017897853cf3ec18fd06c6.tar.xz
Add vector counters to HTTP clients and servers; count the requests by method and responses by method and response code
Diffstat (limited to 'synapse/http/client.py')
-rw-r--r--synapse/http/client.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py
index d61e53bd94..e40e82e80b 100644
--- a/synapse/http/client.py
+++ b/synapse/http/client.py
@@ -15,6 +15,7 @@
 
 from synapse.api.errors import CodeMessageException
 from syutil.jsonutil import encode_canonical_json
+import synapse.metrics
 
 from twisted.internet import defer, reactor
 from twisted.web.client import (
@@ -31,6 +32,15 @@ import urllib
 
 logger = logging.getLogger(__name__)
 
+metrics = synapse.metrics.get_metrics_for(__name__)
+
+outgoing_requests_counter = metrics.register_counter("outgoing_requests",
+    keys=["method"],
+)
+incoming_responses_counter = metrics.register_counter("incoming_responses",
+    keys=["method","code"],
+)
+
 
 class SimpleHttpClient(object):
     """
@@ -48,7 +58,18 @@ class SimpleHttpClient(object):
     def request(self, method, *args, **kwargs):
         # A small wrapper around self.agent.request() so we can easily attach
         # counters to it
-        return self.agent.request(method, *args, **kwargs)
+        outgoing_requests_counter.inc(method)
+        d = self.agent.request(method, *args, **kwargs)
+
+        def _cb(response):
+            incoming_responses_counter.inc(method, response.code)
+            return response
+        def _eb(failure):
+            incoming_responses_counter.inc(method, "ERR")
+            return failure
+        d.addCallbacks(_cb, _eb)
+
+        return d
 
     @defer.inlineCallbacks
     def post_urlencoded_get_json(self, uri, args={}):