Python flask.request.start_time() Examples

The following are 30 code examples of flask.request.start_time(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask.request , or try the search function .
Example #1
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 6 votes vote down vote up
def stop_timer(response):
    # convert this into milliseconds for statsd
    resp_time = (time.time() - request.start_time)*1000
    key = REQUEST_LATENCY_METRIC_KEY_PATTERN.format(
        request.endpoint,
        request.method,
        response.status_code,
    )
    statsd.timing(key, resp_time)

    key = REQUEST_COUNT_METRIC_KEY_PATTERN.format(
        request.endpoint,
        request.method,
        response.status_code,
    )
    statsd.incr(key)
    return response 
Example #2
Source File: __init__.py    From flask-prometheus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def before_request():
	request.start_time = time.time() 
Example #3
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def stop_timer(response):
    resp_time = time.time() - request.start_time
    REQUEST_LATENCY.labels('webapp', request.path, _get_worker_id()).observe(resp_time)
    return response 
Example #4
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #5
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def stop_timer(response):
    resp_time = time.time() - request.start_time
    statsd.histogram(REQUEST_LATENCY_METRIC_NAME,
            resp_time,
            tags=[
                'service:webapp',
                'endpoint:%s' % request.path,
                ]
    )
    return response 
Example #6
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #7
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #8
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def stop_timer(response):
    resp_time = time.time() - request.start_time
    statsd.histogram(REQUEST_LATENCY_METRIC_NAME,
            resp_time,
            tags=[
                'service:webapp',
                'endpoint: %s' % request.path,
                ]
    )
    return response 
Example #9
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #10
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def stop_timer(response):
    resp_time = time.time() - request.start_time
    REQUEST_LATENCY.labels('webapp', request.path).observe(resp_time)
    return response 
Example #11
Source File: middleware.py    From python-prometheus-demo with MIT License 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #12
Source File: flask_common.py    From flask-common with Apache License 2.0 5 votes vote down vote up
def init_app(self, app):
        """Initializes the Flask application with Common."""
        if not hasattr(app, 'extensions'):
            app.extensions = {}

        if 'common' in app.extensions:
            raise RuntimeError("Flask-Common extension already initialized")

        app.extensions['common'] = self
        self.app = app

        if 'COMMON_FILESERVER_DISABLED' not in app.config:
            with app.test_request_context():

                # Configure WhiteNoise.
                app.wsgi_app = WhiteNoise(app.wsgi_app, root=url_for('static', filename='')[1:])

        self.cache = Cache(app, config={'CACHE_TYPE': app.config.get("COMMON_CACHE_TYPE", 'simple')})

        @app.before_request
        def before_request_callback():
            request.start_time = maya.now()

        @app.after_request
        def after_request_callback(response):
            if 'COMMON_POWERED_BY_DISABLED' not in current_app.config:
                response.headers['X-Powered-By'] = 'Flask'
            if 'COMMON_PROCESSED_TIME_DISABLED' not in current_app.config:
                response.headers['X-Processed-Time'] = maya.now().epoch - request.start_time.epoch
            return response

        @app.route('/favicon.ico')
        def favicon():
            return redirect(url_for('static', filename='favicon.ico'), code=301) 
Example #13
Source File: middleware.py    From kqueen with MIT License 5 votes vote down vote up
def record_request_data(response):
    resp_time = time.time() - request.start_time

    REQUEST_LATENCY.labels(request.method, request.path).observe(resp_time)
    REQUEST_COUNT.labels(request.method, request.path, response.status_code).inc()

    return response 
Example #14
Source File: middleware.py    From kqueen with MIT License 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #15
Source File: exampleapp.py    From kfd-flask with Apache License 2.0 5 votes vote down vote up
def after_request(response):
    request_latency = time.time() - request.start_time
    FLASK_REQUEST_LATENCY.labels(request.method, request.path).observe(request_latency)
    FLASK_REQUEST_COUNT.labels(request.method, request.path, response.status_code).inc()
    return response 
Example #16
Source File: exampleapp.py    From kfd-flask with Apache License 2.0 5 votes vote down vote up
def before_request():
    request.start_time = time.time() 
Example #17
Source File: __init__.py    From flask-prometheus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def after_request(response):
	request_latency = time.time() - request.start_time
	FLASK_REQUEST_LATENCY.labels(request.method, request.path).observe(request_latency)
	FLASK_REQUEST_COUNT.labels(request.method, request.path, response.status_code).inc()

	return response 
Example #18
Source File: metrics.py    From pyms with GNU General Public License v3.0 5 votes vote down vote up
def before_request(self):  # pylint: disable=R0201
        request.start_time = time.time() 
Example #19
Source File: __init__.py    From flask-prometheus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def after_request(response):
    request_latency = time.time() - request.start_time
    FLASK_REQUEST_LATENCY.labels(request.method, request.path).observe(request_latency)
    FLASK_REQUEST_COUNT.labels(request.method, request.path, response.status_code).inc()

    return response 
Example #20
Source File: __init__.py    From flask-prometheus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def before_request():
    request.start_time = time.time() 
Example #21
Source File: metrics.py    From c3bottles with MIT License 5 votes vote down vote up
def after_request(response):
    latency = time() - request.start_time
    request_latency.labels(request.method, request.endpoint).observe(latency)
    request_count.labels(request.method, request.endpoint, response.status_code).inc()
    return response 
Example #22
Source File: metrics.py    From c3bottles with MIT License 5 votes vote down vote up
def before_request():
    request.start_time = time() 
Example #23
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def stop_timer(response):
    # convert this into milliseconds for statsd
    resp_time = (time.time() - request.start_time)*1000
    with open('metrics.csv', 'a', newline='') as f:
        csvwriter = csv.writer(f)
        csvwriter.writerow([str(int(time.time())), str(resp_time)])

    return response 
Example #24
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #25
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #26
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #27
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def stop_timer(response):
    # convert this into milliseconds for statsd
    resp_time = (time.time() - request.start_time)*1000
    node_id = node_ids[random.choice(range(len(node_ids)))]
    with open('metrics.csv', 'a', newline='') as f:
        csvwriter = csv.writer(f)
        csvwriter.writerow([
            str(int(time.time())), 'webapp1', node_id,
            request.endpoint, request.method, str(response.status_code),
            str(resp_time)
        ])

    return response 
Example #28
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def start_timer():
    request.start_time = time.time() 
Example #29
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def stop_timer(response):
    resp_time = time.time() - request.start_time
    statsd.histogram(REQUEST_LATENCY_METRIC_NAME,
            resp_time,
            tags=[
                'service:webapp',
                'endpoint: %s' % request.path,
                ]
    )
    return response 
Example #30
Source File: middleware.py    From python-monitoring-talk with Apache License 2.0 5 votes vote down vote up
def start_timer():
    request.start_time = time.time()