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 15import collections 16from typing import List 17 18from grpc_observability._cyobservability import MetricsName 19 20 21class Metric( 22 collections.namedtuple( 23 "Metric", 24 ["name", "cyname", "unit", "description"], 25 ) 26): 27 pass 28 29 30CLIENT_ATTEMPT_STARTED = Metric( 31 "grpc.client.attempt.started", 32 MetricsName.CLIENT_STARTED_RPCS, 33 "{attempt}", 34 "Number of client call attempts started", 35) 36CLIENT_ATTEMPT_DURATION = Metric( 37 "grpc.client.attempt.duration", 38 MetricsName.CLIENT_ROUNDTRIP_LATENCY, 39 "s", 40 "End-to-end time taken to complete a client call attempt", 41) 42CLIENT_RPC_DURATION = Metric( 43 "grpc.client.call.duration", 44 MetricsName.CLIENT_API_LATENCY, 45 "s", 46 "End-to-end time taken to complete a call from client's perspective", 47) 48CLIENT_ATTEMPT_SEND_BYTES = Metric( 49 "grpc.client.attempt.sent_total_compressed_message_size", 50 MetricsName.CLIENT_SEND_BYTES_PER_RPC, 51 "By", 52 "Compressed message bytes sent per client call attempt", 53) 54CLIENT_ATTEMPT_RECEIVED_BYTES = Metric( 55 "grpc.client.attempt.rcvd_total_compressed_message_size", 56 MetricsName.CLIENT_RECEIVED_BYTES_PER_RPC, 57 "By", 58 "Compressed message bytes received per call attempt", 59) 60SERVER_STARTED_RPCS = Metric( 61 "grpc.server.call.started", 62 MetricsName.SERVER_STARTED_RPCS, 63 "{call}", 64 "Number of server calls started", 65) 66SERVER_RPC_DURATION = Metric( 67 "grpc.server.call.duration", 68 MetricsName.SERVER_SERVER_LATENCY, 69 "s", 70 "End-to-end time taken to complete a call from server transport's perspective", 71) 72SERVER_RPC_SEND_BYTES = Metric( 73 "grpc.server.call.sent_total_compressed_message_size", 74 MetricsName.SERVER_SENT_BYTES_PER_RPC, 75 "By", 76 "Compressed message bytes sent per server call", 77) 78SERVER_RPC_RECEIVED_BYTES = Metric( 79 "grpc.server.call.rcvd_total_compressed_message_size", 80 MetricsName.SERVER_RECEIVED_BYTES_PER_RPC, 81 "By", 82 "Compressed message bytes received per server call", 83) 84 85 86def base_metrics() -> List[Metric]: 87 return [ 88 CLIENT_ATTEMPT_STARTED, 89 CLIENT_ATTEMPT_DURATION, 90 CLIENT_RPC_DURATION, 91 CLIENT_ATTEMPT_SEND_BYTES, 92 CLIENT_ATTEMPT_RECEIVED_BYTES, 93 SERVER_STARTED_RPCS, 94 SERVER_RPC_DURATION, 95 SERVER_RPC_SEND_BYTES, 96 SERVER_RPC_RECEIVED_BYTES, 97 ] 98