| OLD | NEW |
| (Empty) |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from infra_libs.ts_mon.common import metrics | |
| 6 | |
| 7 | |
| 8 # Extending HTTP status codes to client-side errors and timeouts. | |
| 9 STATUS_OK = 200 | |
| 10 STATUS_ERROR = 901 | |
| 11 STATUS_TIMEOUT = 902 | |
| 12 STATUS_EXCEPTION = 909 | |
| 13 | |
| 14 | |
| 15 request_bytes = metrics.CumulativeDistributionMetric('http/request_bytes', | |
| 16 description='Bytes sent per http request (body only).') | |
| 17 response_bytes = metrics.CumulativeDistributionMetric('http/response_bytes', | |
| 18 description='Bytes received per http request (content only).') | |
| 19 durations = metrics.CumulativeDistributionMetric('http/durations', | |
| 20 description='Time elapsed between sending a request and getting a' | |
| 21 ' response (including parsing) in milliseconds.') | |
| 22 response_status = metrics.CounterMetric('http/response_status', | |
| 23 description='Number of responses received by HTTP status code.') | |
| 24 | |
| 25 | |
| 26 server_request_bytes = metrics.CumulativeDistributionMetric( | |
| 27 'http/server_request_bytes', | |
| 28 description='Bytes received per http request (body only).') | |
| 29 server_response_bytes = metrics.CumulativeDistributionMetric( | |
| 30 'http/server_response_bytes', | |
| 31 description='Bytes sent per http request (content only).') | |
| 32 server_durations = metrics.CumulativeDistributionMetric('http/server_durations', | |
| 33 description='Time elapsed between receiving a request and sending a' | |
| 34 ' response (including parsing) in milliseconds.') | |
| 35 server_response_status = metrics.CounterMetric('http/server_response_status', | |
| 36 description='Number of responses sent by HTTP status code.') | |
| 37 | |
| 38 | |
| 39 def update_http_server_metrics(endpoint_name, response_status_code, elapsed_ms, | |
| 40 request_size=None, response_size=None, | |
| 41 user_agent=None): | |
| 42 fields = {'status': response_status_code, 'name': endpoint_name, | |
| 43 'is_robot': False} | |
| 44 if user_agent is not None: | |
| 45 # We must not log user agents, but we can store whether or not the | |
| 46 # user agent string indicates that the requester was a Google bot. | |
| 47 fields['is_robot'] = ( | |
| 48 'GoogleBot' in user_agent or | |
| 49 'GoogleSecurityScanner' in user_agent or | |
| 50 user_agent == 'B3M/prober') | |
| 51 | |
| 52 server_durations.add(elapsed_ms, fields=fields) | |
| 53 server_response_status.increment(fields=fields) | |
| 54 if request_size is not None: | |
| 55 server_request_bytes.add(request_size, fields=fields) | |
| 56 if response_size is not None: | |
| 57 server_response_bytes.add(response_size, fields=fields) | |
| OLD | NEW |