client_metrics.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. 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)
  29. )
  30. // Predefined views may be registered to collect data for the above measures.
  31. // As always, you may also define your own custom views over measures collected by this
  32. // package. These are declared as a convenience only; none are registered by
  33. // default.
  34. var (
  35. ClientSentBytesPerRPCView = &view.View{
  36. Measure: ClientSentBytesPerRPC,
  37. Name: "grpc.io/client/sent_bytes_per_rpc",
  38. Description: "Distribution of bytes sent per RPC, by method.",
  39. TagKeys: []tag.Key{KeyClientMethod},
  40. Aggregation: DefaultBytesDistribution,
  41. }
  42. ClientReceivedBytesPerRPCView = &view.View{
  43. Measure: ClientReceivedBytesPerRPC,
  44. Name: "grpc.io/client/received_bytes_per_rpc",
  45. Description: "Distribution of bytes received per RPC, by method.",
  46. TagKeys: []tag.Key{KeyClientMethod},
  47. Aggregation: DefaultBytesDistribution,
  48. }
  49. ClientRoundtripLatencyView = &view.View{
  50. Measure: ClientRoundtripLatency,
  51. Name: "grpc.io/client/roundtrip_latency",
  52. Description: "Distribution of round-trip latency, by method.",
  53. TagKeys: []tag.Key{KeyClientMethod},
  54. Aggregation: DefaultMillisecondsDistribution,
  55. }
  56. ClientCompletedRPCsView = &view.View{
  57. Measure: ClientRoundtripLatency,
  58. Name: "grpc.io/client/completed_rpcs",
  59. Description: "Count of RPCs by method and status.",
  60. TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
  61. Aggregation: view.Count(),
  62. }
  63. ClientSentMessagesPerRPCView = &view.View{
  64. Measure: ClientSentMessagesPerRPC,
  65. Name: "grpc.io/client/sent_messages_per_rpc",
  66. Description: "Distribution of sent messages count per RPC, by method.",
  67. TagKeys: []tag.Key{KeyClientMethod},
  68. Aggregation: DefaultMessageCountDistribution,
  69. }
  70. ClientReceivedMessagesPerRPCView = &view.View{
  71. Measure: ClientReceivedMessagesPerRPC,
  72. Name: "grpc.io/client/received_messages_per_rpc",
  73. Description: "Distribution of received messages count per RPC, by method.",
  74. TagKeys: []tag.Key{KeyClientMethod},
  75. Aggregation: DefaultMessageCountDistribution,
  76. }
  77. ClientServerLatencyView = &view.View{
  78. Measure: ClientServerLatency,
  79. Name: "grpc.io/client/server_latency",
  80. Description: "Distribution of server latency as viewed by client, by method.",
  81. TagKeys: []tag.Key{KeyClientMethod},
  82. Aggregation: DefaultMillisecondsDistribution,
  83. }
  84. )
  85. // DefaultClientViews are the default client views provided by this package.
  86. var DefaultClientViews = []*view.View{
  87. ClientSentBytesPerRPCView,
  88. ClientReceivedBytesPerRPCView,
  89. ClientRoundtripLatencyView,
  90. ClientCompletedRPCsView,
  91. }
  92. // TODO(jbd): Add roundtrip_latency, uncompressed_request_bytes, uncompressed_response_bytes, request_count, response_count.
  93. // TODO(acetechnologist): This is temporary and will need to be replaced by a
  94. // mechanism to load these defaults from a common repository/config shared by
  95. // all supported languages. Likely a serialized protobuf of these defaults.