diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-02-24 19:51:21 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-12 16:24:50 +0000 |
commit | 7d72e44eb9660eaeab017897853cf3ec18fd06c6 (patch) | |
tree | 78c1e01961ab8e8ff36a4def621b7b6f1a3e136b /synapse/http/server.py | |
parent | Pull out all uses of the underlying HTTP user agent .request() method into a ... (diff) | |
download | synapse-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/server.py')
-rw-r--r-- | synapse/http/server.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py index 767c3ef79b..ac893bb40c 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,15 @@ import urllib logger = logging.getLogger(__name__) +metrics = synapse.metrics.get_metrics_for(__name__) + +incoming_requests_counter = metrics.register_counter("incoming_requests", + keys=["method"], +) +outgoing_responses_counter = metrics.register_counter("outgoing_responses", + keys=["method","code"], +) + class HttpServer(object): """ Interface for registering callbacks on a HTTP server @@ -112,6 +122,8 @@ class JsonResource(HttpServer, resource.Resource): This checks if anyone has registered a callback for that method and path. """ + incoming_requests_counter.inc(request.method) + code = None start = self.clock.time_msec() try: @@ -190,6 +202,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, |