Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: client/third_party/infra_libs/ts_mon/common/http_metrics.py

Issue 2705273003: Roll infra_libs and gae_ts_mon in luci-py, and add field_specs to all metrics (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from infra_libs.ts_mon.common import metrics 5 from infra_libs.ts_mon.common import metrics
6 6
7 7
8 # Extending HTTP status codes to client-side errors and timeouts. 8 # Extending HTTP status codes to client-side errors and timeouts.
9 STATUS_OK = 200 9 STATUS_OK = 200
10 STATUS_ERROR = 901 10 STATUS_ERROR = 901
11 STATUS_TIMEOUT = 902 11 STATUS_TIMEOUT = 902
12 STATUS_EXCEPTION = 909 12 STATUS_EXCEPTION = 909
13 13
14
15 request_bytes = metrics.CumulativeDistributionMetric('http/request_bytes', 14 request_bytes = metrics.CumulativeDistributionMetric('http/request_bytes',
16 description='Bytes sent per http request (body only).') 15 'Bytes sent per http request (body only).', [
16 metrics.StringField('name'),
17 metrics.StringField('client'),
18 ])
17 response_bytes = metrics.CumulativeDistributionMetric('http/response_bytes', 19 response_bytes = metrics.CumulativeDistributionMetric('http/response_bytes',
18 description='Bytes received per http request (content only).') 20 'Bytes received per http request (content only).', [
21 metrics.StringField('name'),
22 metrics.StringField('client'),
23 ])
19 durations = metrics.CumulativeDistributionMetric('http/durations', 24 durations = metrics.CumulativeDistributionMetric('http/durations',
20 description='Time elapsed between sending a request and getting a' 25 'Time elapsed between sending a request and getting a'
21 ' response (including parsing) in milliseconds.') 26 ' response (including parsing) in milliseconds.', [
27 metrics.StringField('name'),
28 metrics.StringField('client'),
29 ])
22 response_status = metrics.CounterMetric('http/response_status', 30 response_status = metrics.CounterMetric('http/response_status',
23 description='Number of responses received by HTTP status code.') 31 'Number of responses received by HTTP status code.', [
32 metrics.IntegerField('status'),
33 metrics.StringField('name'),
34 metrics.StringField('client'),
35 ])
24 36
25 37
26 server_request_bytes = metrics.CumulativeDistributionMetric( 38 server_request_bytes = metrics.CumulativeDistributionMetric(
27 'http/server_request_bytes', 39 'http/server_request_bytes',
28 description='Bytes received per http request (body only).') 40 'Bytes received per http request (body only).', [
41 metrics.IntegerField('status'),
42 metrics.StringField('name'),
43 metrics.BooleanField('is_robot'),
44 ])
29 server_response_bytes = metrics.CumulativeDistributionMetric( 45 server_response_bytes = metrics.CumulativeDistributionMetric(
30 'http/server_response_bytes', 46 'http/server_response_bytes',
31 description='Bytes sent per http request (content only).') 47 'Bytes sent per http request (content only).', [
48 metrics.IntegerField('status'),
49 metrics.StringField('name'),
50 metrics.BooleanField('is_robot'),
51 ])
32 server_durations = metrics.CumulativeDistributionMetric('http/server_durations', 52 server_durations = metrics.CumulativeDistributionMetric('http/server_durations',
33 description='Time elapsed between receiving a request and sending a' 53 'Time elapsed between receiving a request and sending a'
34 ' response (including parsing) in milliseconds.') 54 ' response (including parsing) in milliseconds.', [
55 metrics.IntegerField('status'),
56 metrics.StringField('name'),
57 metrics.BooleanField('is_robot'),
58 ])
35 server_response_status = metrics.CounterMetric('http/server_response_status', 59 server_response_status = metrics.CounterMetric('http/server_response_status',
36 description='Number of responses sent by HTTP status code.') 60 'Number of responses sent by HTTP status code.', [
61 metrics.IntegerField('status'),
62 metrics.StringField('name'),
63 metrics.BooleanField('is_robot'),
64 ])
37 65
38 66
39 def update_http_server_metrics(endpoint_name, response_status_code, elapsed_ms, 67 def update_http_server_metrics(endpoint_name, response_status_code, elapsed_ms,
40 request_size=None, response_size=None, 68 request_size=None, response_size=None,
41 user_agent=None): 69 user_agent=None):
42 fields = {'status': response_status_code, 'name': endpoint_name, 70 fields = {'status': response_status_code, 'name': endpoint_name,
43 'is_robot': False} 71 'is_robot': False}
44 if user_agent is not None: 72 if user_agent is not None:
45 # We must not log user agents, but we can store whether or not the 73 # 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. 74 # user agent string indicates that the requester was a Google bot.
47 fields['is_robot'] = ( 75 fields['is_robot'] = (
48 'GoogleBot' in user_agent or 76 'GoogleBot' in user_agent or
49 'GoogleSecurityScanner' in user_agent or 77 'GoogleSecurityScanner' in user_agent or
50 user_agent == 'B3M/prober') 78 user_agent == 'B3M/prober')
51 79
52 server_durations.add(elapsed_ms, fields=fields) 80 server_durations.add(elapsed_ms, fields=fields)
53 server_response_status.increment(fields=fields) 81 server_response_status.increment(fields=fields)
54 if request_size is not None: 82 if request_size is not None:
55 server_request_bytes.add(request_size, fields=fields) 83 server_request_bytes.add(request_size, fields=fields)
56 if response_size is not None: 84 if response_size is not None:
57 server_response_bytes.add(response_size, fields=fields) 85 server_response_bytes.add(response_size, fields=fields)
OLDNEW
« no previous file with comments | « client/third_party/infra_libs/ts_mon/common/errors.py ('k') | client/third_party/infra_libs/ts_mon/common/interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698