client_metrics.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2017, OpenCensus 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. //
  15. package ocgrpc
  16. import (
  17. "go.opencensus.io/stats"
  18. "go.opencensus.io/stats/view"
  19. "go.opencensus.io/tag"
  20. )
  21. // The following variables are measures are recorded by ClientHandler:
  22. var (
  23. ClientSentMessagesPerRPC = stats.Int64("grpc.io/client/sent_messages_per_rpc", "Number of messages sent in the RPC (always 1 for non-streaming RPCs).", stats.UnitDimensionless)
  24. ClientSentBytesPerRPC = stats.Int64("grpc.io/client/sent_bytes_per_rpc", "Total bytes sent across all request messages per RPC.", stats.UnitBytes)
  25. ClientReceivedMessagesPerRPC = stats.Int64("grpc.io/client/received_messages_per_rpc", "Number of response messages received per RPC (always 1 for non-streaming RPCs).", stats.UnitDimensionless)
  26. ClientReceivedBytesPerRPC = stats.Int64("grpc.io/client/received_bytes_per_rpc", "Total bytes received across all response messages per RPC.", stats.UnitBytes)
  27. ClientRoundtripLatency = stats.Float64("grpc.io/client/roundtrip_latency", "Time between first byte of request sent to last byte of response received, or terminal error.", stats.UnitMilliseconds)
  28. ClientStartedRPCs = stats.Int64("grpc.io/client/started_rpcs", "Number of started client RPCs.", stats.UnitDimensionless)
  29. ClientServerLatency = stats.Float64("grpc.io/client/server_latency", `Propagated from the server and should have the same value as "grpc.io/server/latency".`, stats.UnitMilliseconds)
  30. )
  31. // Predefined views may be registered to collect data for the above measures.
  32. // As always, you may also define your own custom views over measures collected by this
  33. // package. These are declared as a convenience only; none are registered by
  34. // default.
  35. var (
  36. ClientSentBytesPerRPCView = &view.View{
  37. Measure: ClientSentBytesPerRPC,
  38. Name: "grpc.io/client/sent_bytes_per_rpc",
  39. Description: "Distribution of bytes sent per RPC, by method.",
  40. TagKeys: []tag.Key{KeyClientMethod},
  41. Aggregation: DefaultBytesDistribution,
  42. }
  43. ClientReceivedBytesPerRPCView = &view.View{
  44. Measure: ClientReceivedBytesPerRPC,
  45. Name: "grpc.io/client/received_bytes_per_rpc",
  46. Description: "Distribution of bytes received per RPC, by method.",
  47. TagKeys: []tag.Key{KeyClientMethod},
  48. Aggregation: DefaultBytesDistribution,
  49. }
  50. ClientRoundtripLatencyView = &view.View{
  51. Measure: ClientRoundtripLatency,
  52. Name: "grpc.io/client/roundtrip_latency",
  53. Description: "Distribution of round-trip latency, by method.",
  54. TagKeys: []tag.Key{KeyClientMethod},
  55. Aggregation: DefaultMillisecondsDistribution,
  56. }
  57. // Purposely reuses the count from `ClientRoundtripLatency`, tagging
  58. // with method and status to result in ClientCompletedRpcs.
  59. ClientCompletedRPCsView = &view.View{
  60. Measure: ClientRoundtripLatency,
  61. Name: "grpc.io/client/completed_rpcs",
  62. Description: "Count of RPCs by method and status.",
  63. TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
  64. Aggregation: view.Count(),
  65. }
  66. ClientStartedRPCsView = &view.View{
  67. Measure: ClientStartedRPCs,
  68. Name: "grpc.io/client/started_rpcs",
  69. Description: "Number of started client RPCs.",
  70. TagKeys: []tag.Key{KeyClientMethod},
  71. Aggregation: view.Count(),
  72. }
  73. ClientSentMessagesPerRPCView = &view.View{
  74. Measure: ClientSentMessagesPerRPC,
  75. Name: "grpc.io/client/sent_messages_per_rpc",
  76. Description: "Distribution of sent messages count per RPC, by method.",
  77. TagKeys: []tag.Key{KeyClientMethod},
  78. Aggregation: DefaultMessageCountDistribution,
  79. }
  80. ClientReceivedMessagesPerRPCView = &view.View{
  81. Measure: ClientReceivedMessagesPerRPC,
  82. Name: "grpc.io/client/received_messages_per_rpc",
  83. Description: "Distribution of received messages count per RPC, by method.",
  84. TagKeys: []tag.Key{KeyClientMethod},
  85. Aggregation: DefaultMessageCountDistribution,
  86. }
  87. ClientServerLatencyView = &view.View{
  88. Measure: ClientServerLatency,
  89. Name: "grpc.io/client/server_latency",
  90. Description: "Distribution of server latency as viewed by client, by method.",
  91. TagKeys: []tag.Key{KeyClientMethod},
  92. Aggregation: DefaultMillisecondsDistribution,
  93. }
  94. )
  95. // DefaultClientViews are the default client views provided by this package.
  96. var DefaultClientViews = []*view.View{
  97. ClientSentBytesPerRPCView,
  98. ClientReceivedBytesPerRPCView,
  99. ClientRoundtripLatencyView,
  100. ClientCompletedRPCsView,
  101. }
  102. // TODO(jbd): Add roundtrip_latency, uncompressed_request_bytes, uncompressed_response_bytes, request_count, response_count.
  103. // TODO(acetechnologist): This is temporary and will need to be replaced by a
  104. // mechanism to load these defaults from a common repository/config shared by
  105. // all supported languages. Likely a serialized protobuf of these defaults.