# HG changeset patch # User Marcin Kuzminski # Date 2019-07-29 10:44:22 # Node ID 9c4996556d4d7b5cf541bed186eddce9c6f3958b # Parent 114e4e435978fc7a0ed73e6d85fadc7a8d58928f request-wrapper: add request counter. diff --git a/vcsserver/http_main.py b/vcsserver/http_main.py --- a/vcsserver/http_main.py +++ b/vcsserver/http_main.py @@ -331,6 +331,9 @@ class HTTPApplication(object): self.config.add_tween( 'vcsserver.tweens.request_wrapper.RequestWrapperTween', ) + self.config.add_request_method( + 'vcsserver.lib.request_counter.get_request_counter', + 'request_count') def wsgi_app(self): return self.config.make_wsgi_app() diff --git a/vcsserver/lib/request_counter.py b/vcsserver/lib/request_counter.py new file mode 100644 --- /dev/null +++ b/vcsserver/lib/request_counter.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +# RhodeCode VCSServer provides access to different vcs backends via network. +# Copyright (C) 2014-2019 RhodeCode GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + +counter = 0 + + +def get_request_counter(request): + global counter + counter += 1 + return counter diff --git a/vcsserver/tweens/request_wrapper.py b/vcsserver/tweens/request_wrapper.py --- a/vcsserver/tweens/request_wrapper.py +++ b/vcsserver/tweens/request_wrapper.py @@ -50,9 +50,10 @@ class RequestWrapperTween(object): finally: end = time.time() total = end - start + count = request.request_count() log.info( - 'IP: %s %s Request to %s time: %.4fs [%s]', - '127.0.0.1', request.environ.get('REQUEST_METHOD'), + 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s]', + count, '127.0.0.1', request.environ.get('REQUEST_METHOD'), safe_str(get_access_path(request)), total, get_user_agent(request.environ)) return response