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

Side by Side Diff: common/tsmon/metric/standard_metrics.go

Issue 2123853002: Added unit annotation supports onto tsmon in go. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Specify the unit of logdog/collector/subscription/processing_time_ms with types.Milliseconds Created 4 years, 5 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
« no previous file with comments | « common/tsmon/metric/metric_test.go ('k') | common/tsmon/monitor/acq.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package metric 5 package metric
6 6
7 import ( 7 import (
8 "strings" 8 "strings"
9 "time" 9 "time"
10 10
11 "golang.org/x/net/context" 11 "golang.org/x/net/context"
12 12
13 "github.com/luci/luci-go/common/tsmon/distribution" 13 "github.com/luci/luci-go/common/tsmon/distribution"
14 "github.com/luci/luci-go/common/tsmon/field" 14 "github.com/luci/luci-go/common/tsmon/field"
15 "github.com/luci/luci-go/common/tsmon/types"
15 ) 16 )
16 17
17 // Metrics common to all tasks and devices. 18 // Metrics common to all tasks and devices.
18 var ( 19 var (
19 presenceMetric = NewBool( 20 presenceMetric = NewBool(
20 "presence/up", 21 "presence/up",
21 » » "Set to True when the program is running, missing otherwise.") 22 » » "Set to True when the program is running, missing otherwise.",
23 » » types.MetricMetadata{})
22 ) 24 )
23 25
24 // Standard metrics for all requests to remote endpoints. These 26 // Standard metrics for all requests to remote endpoints. These
25 // metrics should be consistent across all tsmon implementations, 27 // metrics should be consistent across all tsmon implementations,
26 // Python or Go. 28 // Python or Go.
27 var ( 29 var (
28 requestBytesMetric = NewCumulativeDistribution( 30 requestBytesMetric = NewCumulativeDistribution(
29 "http/request_bytes", 31 "http/request_bytes",
30 "Bytes sent per http request (body only).", 32 "Bytes sent per http request (body only).",
33 types.MetricMetadata{Units: types.Bytes},
31 distribution.DefaultBucketer, 34 distribution.DefaultBucketer,
32 field.String("name"), // Usually the requested service name 35 field.String("name"), // Usually the requested service name
33 field.String("client")) // http client used, e.g. urlfetch 36 field.String("client")) // http client used, e.g. urlfetch
34 37
35 responseBytesMetric = NewCumulativeDistribution( 38 responseBytesMetric = NewCumulativeDistribution(
36 "http/response_bytes", 39 "http/response_bytes",
37 "Bytes received per http request (content only).", 40 "Bytes received per http request (content only).",
41 types.MetricMetadata{Units: types.Bytes},
38 distribution.DefaultBucketer, 42 distribution.DefaultBucketer,
39 field.String("name"), // Usually the requested service name 43 field.String("name"), // Usually the requested service name
40 field.String("client")) // http client used, e.g. urlfetch 44 field.String("client")) // http client used, e.g. urlfetch
41 45
42 requestDurationsMetric = NewCumulativeDistribution( 46 requestDurationsMetric = NewCumulativeDistribution(
43 "http/durations", 47 "http/durations",
44 "Time elapsed between sending a request and getting a response ( including parsing) in milliseconds.", 48 "Time elapsed between sending a request and getting a response ( including parsing) in milliseconds.",
49 types.MetricMetadata{Units: types.Milliseconds},
45 distribution.DefaultBucketer, 50 distribution.DefaultBucketer,
46 field.String("name"), // Usually the requested service name 51 field.String("name"), // Usually the requested service name
47 field.String("client")) // http client used, e.g. urlfetch 52 field.String("client")) // http client used, e.g. urlfetch
48 53
49 responseStatusMetric = NewCounter( 54 responseStatusMetric = NewCounter(
50 "http/response_status", 55 "http/response_status",
51 "Number of responses received by HTTP status code.", 56 "Number of responses received by HTTP status code.",
57 types.MetricMetadata{},
52 field.Int("status"), // HTTP status code 58 field.Int("status"), // HTTP status code
53 field.String("name"), // Usually the requested service name 59 field.String("name"), // Usually the requested service name
54 field.String("client")) // http client used, e.g. urlfetch 60 field.String("client")) // http client used, e.g. urlfetch
55 ) 61 )
56 62
57 // Standard metrics for server-side request handlers. These metrics 63 // Standard metrics for server-side request handlers. These metrics
58 // should be consistent across all tsmon implementations, Python or 64 // should be consistent across all tsmon implementations, Python or
59 // Go. 65 // Go.
60 var ( 66 var (
61 serverRequestBytesMetric = NewCumulativeDistribution( 67 serverRequestBytesMetric = NewCumulativeDistribution(
62 "http/server_request_bytes", 68 "http/server_request_bytes",
63 "Bytes received per http request (body only).", 69 "Bytes received per http request (body only).",
70 types.MetricMetadata{Units: types.Bytes},
64 distribution.DefaultBucketer, 71 distribution.DefaultBucketer,
65 field.Int("status"), // HTTP status code 72 field.Int("status"), // HTTP status code
66 field.String("name"), // URL template 73 field.String("name"), // URL template
67 field.Bool("is_robot")) // If request is made by a bot 74 field.Bool("is_robot")) // If request is made by a bot
68 75
69 serverResponseBytesMetric = NewCumulativeDistribution( 76 serverResponseBytesMetric = NewCumulativeDistribution(
70 "http/server_response_bytes", 77 "http/server_response_bytes",
71 "Bytes sent per http request (body only).", 78 "Bytes sent per http request (body only).",
79 types.MetricMetadata{Units: types.Bytes},
72 distribution.DefaultBucketer, 80 distribution.DefaultBucketer,
73 field.Int("status"), // HTTP status code 81 field.Int("status"), // HTTP status code
74 field.String("name"), // URL template 82 field.String("name"), // URL template
75 field.Bool("is_robot")) // If request is made by a bot 83 field.Bool("is_robot")) // If request is made by a bot
76 84
77 serverDurationsMetric = NewCumulativeDistribution( 85 serverDurationsMetric = NewCumulativeDistribution(
78 "http/server_durations", 86 "http/server_durations",
79 "Time elapsed between receiving a request and sending a response (including parsing) in milliseconds.", 87 "Time elapsed between receiving a request and sending a response (including parsing) in milliseconds.",
88 types.MetricMetadata{Units: types.Milliseconds},
80 distribution.DefaultBucketer, 89 distribution.DefaultBucketer,
81 field.Int("status"), // HTTP status code 90 field.Int("status"), // HTTP status code
82 field.String("name"), // URL template 91 field.String("name"), // URL template
83 field.Bool("is_robot")) // If request is made by a bot 92 field.Bool("is_robot")) // If request is made by a bot
84 93
85 serverResponseStatusMetric = NewCounter( 94 serverResponseStatusMetric = NewCounter(
86 "http/server_response_status", 95 "http/server_response_status",
87 "Number of responses sent by HTTP status code.", 96 "Number of responses sent by HTTP status code.",
97 types.MetricMetadata{},
88 field.Int("status"), // HTTP status code 98 field.Int("status"), // HTTP status code
89 field.String("name"), // URL template 99 field.String("name"), // URL template
90 field.Bool("is_robot")) // If request is made by a bot 100 field.Bool("is_robot")) // If request is made by a bot
91 101
92 ) 102 )
93 103
94 // UpdatePresenceMetrics sets the presence/up metric. 104 // UpdatePresenceMetrics sets the presence/up metric.
95 func UpdatePresenceMetrics(ctx context.Context) { 105 func UpdatePresenceMetrics(ctx context.Context) {
96 presenceMetric.Set(ctx, true) 106 presenceMetric.Set(ctx, true)
97 } 107 }
(...skipping 17 matching lines...) Expand all
115 userAgent string) { 125 userAgent string) {
116 isRobot := (strings.Contains(userAgent, "GoogleBot") || 126 isRobot := (strings.Contains(userAgent, "GoogleBot") ||
117 strings.Contains(userAgent, "GoogleSecurityScanner") || 127 strings.Contains(userAgent, "GoogleSecurityScanner") ||
118 userAgent == "B3M/prober") 128 userAgent == "B3M/prober")
119 serverDurationsMetric.Add(ctx, duration.Seconds()*millisecondsInASecond, 129 serverDurationsMetric.Add(ctx, duration.Seconds()*millisecondsInASecond,
120 code, name, isRobot) 130 code, name, isRobot)
121 serverResponseStatusMetric.Add(ctx, 1, code, name, isRobot) 131 serverResponseStatusMetric.Add(ctx, 1, code, name, isRobot)
122 serverRequestBytesMetric.Add(ctx, float64(requestBytes), code, name, isR obot) 132 serverRequestBytesMetric.Add(ctx, float64(requestBytes), code, name, isR obot)
123 serverResponseBytesMetric.Add(ctx, float64(responseBytes), code, name, i sRobot) 133 serverResponseBytesMetric.Add(ctx, float64(responseBytes), code, name, i sRobot)
124 } 134 }
OLDNEW
« no previous file with comments | « common/tsmon/metric/metric_test.go ('k') | common/tsmon/monitor/acq.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698