##// END OF EJS Templates
request-wrapper: add request counter.
marcink -
r756:9c499655 default
parent child Browse files
Show More
@@ -0,0 +1,27 b''
1 # -*- coding: utf-8 -*-
2
3 # RhodeCode VCSServer provides access to different vcs backends via network.
4 # Copyright (C) 2014-2019 RhodeCode GmbH
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20
21 counter = 0
22
23
24 def get_request_counter(request):
25 global counter
26 counter += 1
27 return counter
@@ -331,6 +331,9 b' class HTTPApplication(object):'
331 self.config.add_tween(
331 self.config.add_tween(
332 'vcsserver.tweens.request_wrapper.RequestWrapperTween',
332 'vcsserver.tweens.request_wrapper.RequestWrapperTween',
333 )
333 )
334 self.config.add_request_method(
335 'vcsserver.lib.request_counter.get_request_counter',
336 'request_count')
334
337
335 def wsgi_app(self):
338 def wsgi_app(self):
336 return self.config.make_wsgi_app()
339 return self.config.make_wsgi_app()
@@ -50,9 +50,10 b' class RequestWrapperTween(object):'
50 finally:
50 finally:
51 end = time.time()
51 end = time.time()
52 total = end - start
52 total = end - start
53 count = request.request_count()
53 log.info(
54 log.info(
54 'IP: %s %s Request to %s time: %.4fs [%s]',
55 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s]',
55 '127.0.0.1', request.environ.get('REQUEST_METHOD'),
56 count, '127.0.0.1', request.environ.get('REQUEST_METHOD'),
56 safe_str(get_access_path(request)), total, get_user_agent(request.environ))
57 safe_str(get_access_path(request)), total, get_user_agent(request.environ))
57
58
58 return response
59 return response
General Comments 0
You need to be logged in to leave comments. Login now