• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from opencensus.stats import measure
16
17# These measure definitions should be kept in sync across opencensus implementations.
18# https://github.com/census-instrumentation/opencensus-java/blob/master/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java.
19
20# Unit constatns
21UNIT_BYTES = "By"
22UNIT_MILLISECONDS = "ms"
23UNIT_COUNT = "1"
24
25# Client
26CLIENT_STARTED_RPCS_MEASURE = measure.MeasureInt(
27    "grpc.io/client/started_rpcs",
28    "The total number of client RPCs ever opened, including those that have not been completed.",
29    UNIT_COUNT,
30)
31
32CLIENT_COMPLETED_RPCS_MEASURE = measure.MeasureInt(
33    "grpc.io/client/completed_rpcs",
34    "The total number of completed client RPCs",
35    UNIT_COUNT,
36)
37
38CLIENT_ROUNDTRIP_LATENCY_MEASURE = measure.MeasureFloat(
39    "grpc.io/client/roundtrip_latency",
40    "Time between first byte of request sent to last byte of response received, or terminal error",
41    UNIT_MILLISECONDS,
42)
43
44CLIENT_API_LATENCY_MEASURE = measure.MeasureInt(
45    "grpc.io/client/api_latency",
46    "End-to-end time taken to complete an RPC",
47    UNIT_MILLISECONDS,
48)
49
50CLIENT_SEND_BYTES_PER_RPC_MEASURE = measure.MeasureFloat(
51    "grpc.io/client/sent_bytes_per_rpc",
52    "Total bytes sent across all request messages per RPC",
53    UNIT_BYTES,
54)
55
56CLIENT_RECEIVED_BYTES_PER_RPC_MEASURE = measure.MeasureFloat(
57    "grpc.io/client/received_bytes_per_rpc",
58    "Total bytes received across all response messages per RPC",
59    UNIT_BYTES,
60)
61
62# Server
63SERVER_STARTED_RPCS_MEASURE = measure.MeasureInt(
64    "grpc.io/server/started_rpcs",
65    "Total bytes sent across all request messages per RPC",
66    UNIT_COUNT,
67)
68
69SERVER_COMPLETED_RPCS_MEASURE = measure.MeasureInt(
70    "grpc.io/server/completed_rpcs",
71    "The total number of completed server RPCs",
72    UNIT_COUNT,
73)
74
75SERVER_SENT_BYTES_PER_RPC_MEASURE = measure.MeasureFloat(
76    "grpc.io/server/sent_bytes_per_rpc",
77    "Total bytes sent across all messages per RPC",
78    UNIT_BYTES,
79)
80
81SERVER_RECEIVED_BYTES_PER_RPC_MEASURE = measure.MeasureFloat(
82    "grpc.io/server/received_bytes_per_rpc",
83    "Total bytes received across all messages per RPC",
84    UNIT_BYTES,
85)
86
87SERVER_SERVER_LATENCY_MEASURE = measure.MeasureFloat(
88    "grpc.io/server/server_latency",
89    "Time between first byte of request received to last byte of response sent, or terminal error",
90    UNIT_MILLISECONDS,
91)
92