|
| 1 | +package metric |
| 2 | + |
| 3 | +import ( |
| 4 | + "go.opencensus.io/plugin/ochttp" |
| 5 | + "go.opencensus.io/stats/view" |
| 6 | + "go.opencensus.io/tag" |
| 7 | +) |
| 8 | + |
| 9 | +var ( |
| 10 | + defaultSizeDistribution = view.Distribution(1024, 2048, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456, 1073741824, 4294967296) |
| 11 | + defaultLatencyDistribution = view.Distribution(1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000) |
| 12 | +) |
| 13 | + |
| 14 | +var ( |
| 15 | + httpViews = []*view.View{ |
| 16 | + &view.View{ |
| 17 | + Name: "relay/http/request_count", |
| 18 | + Description: "Count of HTTP requests started", |
| 19 | + TagKeys: []tag.Key{ochttp.Path, ochttp.Method, ochttp.StatusCode}, |
| 20 | + Measure: ochttp.ServerRequestCount, |
| 21 | + Aggregation: view.Count(), |
| 22 | + }, |
| 23 | + &view.View{ |
| 24 | + Name: "relay/http/request_bytes", |
| 25 | + Description: "Size distribution of HTTP request body", |
| 26 | + TagKeys: []tag.Key{ochttp.Path, ochttp.Method, ochttp.StatusCode}, |
| 27 | + Measure: ochttp.ServerRequestBytes, |
| 28 | + Aggregation: defaultSizeDistribution, |
| 29 | + }, |
| 30 | + &view.View{ |
| 31 | + Name: "relay/http/response_bytes", |
| 32 | + Description: "Size distribution of HTTP response body", |
| 33 | + TagKeys: []tag.Key{ochttp.Path, ochttp.Method, ochttp.StatusCode}, |
| 34 | + Measure: ochttp.ServerResponseBytes, |
| 35 | + Aggregation: defaultSizeDistribution, |
| 36 | + }, |
| 37 | + &view.View{ |
| 38 | + Name: "relay/http/latency", |
| 39 | + Description: "Latency distribution of HTTP requests", |
| 40 | + TagKeys: []tag.Key{ochttp.Path, ochttp.Method, ochttp.StatusCode}, |
| 41 | + Measure: ochttp.ServerLatency, |
| 42 | + Aggregation: defaultLatencyDistribution, |
| 43 | + }, |
| 44 | + &view.View{ |
| 45 | + Name: "relay/http/request_count_by_method", |
| 46 | + Description: "Server request count by HTTP method", |
| 47 | + TagKeys: []tag.Key{ochttp.Path, ochttp.Method, ochttp.StatusCode}, |
| 48 | + Measure: ochttp.ServerRequestCount, |
| 49 | + Aggregation: view.Count(), |
| 50 | + }, |
| 51 | + &view.View{ |
| 52 | + Name: "relay/http/response_count_by_status_code", |
| 53 | + Description: "Server response count by status code", |
| 54 | + TagKeys: []tag.Key{ochttp.Path, ochttp.Method, ochttp.StatusCode}, |
| 55 | + Measure: ochttp.ServerLatency, |
| 56 | + Aggregation: view.Count(), |
| 57 | + }, |
| 58 | + } |
| 59 | + |
| 60 | + httpOutputViews = []*view.View{ |
| 61 | + &view.View{ |
| 62 | + Name: "relay/http/output/sent_bytes", |
| 63 | + Description: "Total bytes sent in request body (not including headers), by HTTP method and response status", |
| 64 | + TagKeys: []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientPath, ochttp.KeyClientMethod, ochttp.KeyClientStatus}, |
| 65 | + Measure: ochttp.ClientSentBytes, |
| 66 | + Aggregation: defaultSizeDistribution, |
| 67 | + }, |
| 68 | + &view.View{ |
| 69 | + Name: "relay/http/output/received_bytes", |
| 70 | + Description: "Total bytes received in response bodies (not including headers but including error responses with bodies), by HTTP method and response status", |
| 71 | + TagKeys: []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientPath, ochttp.KeyClientMethod, ochttp.KeyClientStatus}, |
| 72 | + Measure: ochttp.ClientReceivedBytes, |
| 73 | + Aggregation: defaultSizeDistribution, |
| 74 | + }, |
| 75 | + &view.View{ |
| 76 | + Name: "relay/http/output/latency", |
| 77 | + Description: "End-to-end latency, by HTTP method and response status", |
| 78 | + TagKeys: []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientPath, ochttp.KeyClientMethod, ochttp.KeyClientStatus}, |
| 79 | + Measure: ochttp.ClientRoundtripLatency, |
| 80 | + Aggregation: defaultSizeDistribution, |
| 81 | + }, |
| 82 | + &view.View{ |
| 83 | + Name: "relay/http/output/completed_count", |
| 84 | + Description: "Count of completed requests, by HTTP method and response status", |
| 85 | + TagKeys: []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientPath, ochttp.KeyClientMethod, ochttp.KeyClientStatus}, |
| 86 | + Measure: ochttp.ClientRoundtripLatency, |
| 87 | + Aggregation: view.Count(), |
| 88 | + }, |
| 89 | + } |
| 90 | +) |
| 91 | + |
| 92 | +func init() { |
| 93 | + view.Register(httpViews...) |
| 94 | + view.Register(httpOutputViews...) |
| 95 | +} |
0 commit comments