mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-09-08 17:41:58 +00:00
Count incoming HTTP requests per servlet that responds
This commit is contained in:
parent
4d661ec0f3
commit
1748605c5d
@ -148,6 +148,10 @@ class BaseFederationServlet(object):
|
|||||||
logger.exception("authenticate_request failed")
|
logger.exception("authenticate_request failed")
|
||||||
raise
|
raise
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
||||||
|
# Extra logic that functools.wraps() doesn't finish
|
||||||
|
new_code.__self__ = code.__self__
|
||||||
|
|
||||||
return new_code
|
return new_code
|
||||||
|
|
||||||
def register(self, server):
|
def register(self, server):
|
||||||
|
@ -38,7 +38,7 @@ logger = logging.getLogger(__name__)
|
|||||||
metrics = synapse.metrics.get_metrics_for(__name__)
|
metrics = synapse.metrics.get_metrics_for(__name__)
|
||||||
|
|
||||||
incoming_requests_counter = metrics.register_counter("requests",
|
incoming_requests_counter = metrics.register_counter("requests",
|
||||||
labels=["method"],
|
labels=["method", "servlet"],
|
||||||
)
|
)
|
||||||
outgoing_responses_counter = metrics.register_counter("responses",
|
outgoing_responses_counter = metrics.register_counter("responses",
|
||||||
labels=["method","code"],
|
labels=["method","code"],
|
||||||
@ -122,8 +122,6 @@ class JsonResource(HttpServer, resource.Resource):
|
|||||||
This checks if anyone has registered a callback for that method and
|
This checks if anyone has registered a callback for that method and
|
||||||
path.
|
path.
|
||||||
"""
|
"""
|
||||||
incoming_requests_counter.inc(request.method)
|
|
||||||
|
|
||||||
code = None
|
code = None
|
||||||
start = self.clock.time_msec()
|
start = self.clock.time_msec()
|
||||||
try:
|
try:
|
||||||
@ -143,6 +141,15 @@ class JsonResource(HttpServer, resource.Resource):
|
|||||||
# returned response. We pass both the request and any
|
# returned response. We pass both the request and any
|
||||||
# matched groups from the regex to the callback.
|
# 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 = [
|
args = [
|
||||||
urllib.unquote(u).decode("UTF-8") for u in m.groups()
|
urllib.unquote(u).decode("UTF-8") for u in m.groups()
|
||||||
]
|
]
|
||||||
@ -152,10 +159,7 @@ class JsonResource(HttpServer, resource.Resource):
|
|||||||
request.method, request.path
|
request.method, request.path
|
||||||
)
|
)
|
||||||
|
|
||||||
code, response = yield path_entry.callback(
|
code, response = yield callback(request, *args)
|
||||||
request,
|
|
||||||
*args
|
|
||||||
)
|
|
||||||
|
|
||||||
self._send_response(request, code, response)
|
self._send_response(request, code, response)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user