1 /*
2 *
3 * Copyright 2018 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <grpc/support/port_platform.h>
20
21 #include "src/cpp/ext/filters/census/measures.h"
22
23 #include "opencensus/stats/stats.h"
24 #include "src/cpp/ext/filters/census/grpc_plugin.h"
25
26 namespace grpc {
27
28 using ::opencensus::stats::MeasureDouble;
29 using ::opencensus::stats::MeasureInt64;
30
31 // These measure definitions should be kept in sync across opencensus
32 // implementations--see
33 // https://github.com/census-instrumentation/opencensus-java/blob/master/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java.
34
35 namespace {
36
37 // Unit constants
38 constexpr char kUnitBytes[] = "By";
39 constexpr char kUnitMilliseconds[] = "ms";
40 constexpr char kCount[] = "1";
41
42 } // namespace
43
44 // Client
RpcClientSentBytesPerRpc()45 MeasureDouble RpcClientSentBytesPerRpc() {
46 static const auto measure = MeasureDouble::Register(
47 kRpcClientSentBytesPerRpcMeasureName,
48 "Total bytes sent across all request messages per RPC", kUnitBytes);
49 return measure;
50 }
51
RpcClientReceivedBytesPerRpc()52 MeasureDouble RpcClientReceivedBytesPerRpc() {
53 static const auto measure = MeasureDouble::Register(
54 kRpcClientReceivedBytesPerRpcMeasureName,
55 "Total bytes received across all response messages per RPC", kUnitBytes);
56 return measure;
57 }
58
RpcClientRoundtripLatency()59 MeasureDouble RpcClientRoundtripLatency() {
60 static const auto measure = MeasureDouble::Register(
61 kRpcClientRoundtripLatencyMeasureName,
62 "Time between first byte of request sent to last byte of response "
63 "received, or terminal error",
64 kUnitMilliseconds);
65 return measure;
66 }
67
RpcClientServerLatency()68 MeasureDouble RpcClientServerLatency() {
69 static const auto measure = MeasureDouble::Register(
70 kRpcClientServerLatencyMeasureName,
71 "Time between first byte of request received to last byte of response "
72 "sent, or terminal error (propagated from the server)",
73 kUnitMilliseconds);
74 return measure;
75 }
76
RpcClientSentMessagesPerRpc()77 MeasureInt64 RpcClientSentMessagesPerRpc() {
78 static const auto measure =
79 MeasureInt64::Register(kRpcClientSentMessagesPerRpcMeasureName,
80 "Number of messages sent per RPC", kCount);
81 return measure;
82 }
83
RpcClientReceivedMessagesPerRpc()84 MeasureInt64 RpcClientReceivedMessagesPerRpc() {
85 static const auto measure =
86 MeasureInt64::Register(kRpcClientReceivedMessagesPerRpcMeasureName,
87 "Number of messages received per RPC", kCount);
88 return measure;
89 }
90
91 // Server
RpcServerSentBytesPerRpc()92 MeasureDouble RpcServerSentBytesPerRpc() {
93 static const auto measure = MeasureDouble::Register(
94 kRpcServerSentBytesPerRpcMeasureName,
95 "Total bytes sent across all messages per RPC", kUnitBytes);
96 return measure;
97 }
98
RpcServerReceivedBytesPerRpc()99 MeasureDouble RpcServerReceivedBytesPerRpc() {
100 static const auto measure = MeasureDouble::Register(
101 kRpcServerReceivedBytesPerRpcMeasureName,
102 "Total bytes received across all messages per RPC", kUnitBytes);
103 return measure;
104 }
105
RpcServerServerLatency()106 MeasureDouble RpcServerServerLatency() {
107 static const auto measure = MeasureDouble::Register(
108 kRpcServerServerLatencyMeasureName,
109 "Time between first byte of request received to last byte of response "
110 "sent, or terminal error",
111 kUnitMilliseconds);
112 return measure;
113 }
114
RpcServerSentMessagesPerRpc()115 MeasureInt64 RpcServerSentMessagesPerRpc() {
116 static const auto measure =
117 MeasureInt64::Register(kRpcServerSentMessagesPerRpcMeasureName,
118 "Number of messages sent per RPC", kCount);
119 return measure;
120 }
121
RpcServerReceivedMessagesPerRpc()122 MeasureInt64 RpcServerReceivedMessagesPerRpc() {
123 static const auto measure =
124 MeasureInt64::Register(kRpcServerReceivedMessagesPerRpcMeasureName,
125 "Number of messages received per RPC", kCount);
126 return measure;
127 }
128
129 } // namespace grpc
130