server_metrics.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 ServerHandler:
  22. var (
  23. ServerReceivedMessagesPerRPC = stats.Int64("grpc.io/server/received_messages_per_rpc", "Number of messages received in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless)
  24. ServerReceivedBytesPerRPC = stats.Int64("grpc.io/server/received_bytes_per_rpc", "Total bytes received across all messages per RPC.", stats.UnitBytes)
  25. ServerSentMessagesPerRPC = stats.Int64("grpc.io/server/sent_messages_per_rpc", "Number of messages sent in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless)
  26. ServerSentBytesPerRPC = stats.Int64("grpc.io/server/sent_bytes_per_rpc", "Total bytes sent in across all response messages per RPC.", stats.UnitBytes)
  27. ServerStartedRPCs = stats.Int64("grpc.io/server/started_rpcs", "Number of started server RPCs.", stats.UnitDimensionless)
  28. ServerLatency = stats.Float64("grpc.io/server/server_latency", "Time between first byte of request received to last byte of response sent, or terminal error.", stats.UnitMilliseconds)
  29. )
  30. // TODO(acetechnologist): This is temporary and will need to be replaced by a
  31. // mechanism to load these defaults from a common repository/config shared by
  32. // all supported languages. Likely a serialized protobuf of these defaults.
  33. // Predefined views may be registered to collect data for the above measures.
  34. // As always, you may also define your own custom views over measures collected by this
  35. // package. These are declared as a convenience only; none are registered by
  36. // default.
  37. var (
  38. ServerReceivedBytesPerRPCView = &view.View{
  39. Name: "grpc.io/server/received_bytes_per_rpc",
  40. Description: "Distribution of received bytes per RPC, by method.",
  41. Measure: ServerReceivedBytesPerRPC,
  42. TagKeys: []tag.Key{KeyServerMethod},
  43. Aggregation: DefaultBytesDistribution,
  44. }
  45. ServerSentBytesPerRPCView = &view.View{
  46. Name: "grpc.io/server/sent_bytes_per_rpc",
  47. Description: "Distribution of total sent bytes per RPC, by method.",
  48. Measure: ServerSentBytesPerRPC,
  49. TagKeys: []tag.Key{KeyServerMethod},
  50. Aggregation: DefaultBytesDistribution,
  51. }
  52. ServerLatencyView = &view.View{
  53. Name: "grpc.io/server/server_latency",
  54. Description: "Distribution of server latency in milliseconds, by method.",
  55. TagKeys: []tag.Key{KeyServerMethod},
  56. Measure: ServerLatency,
  57. Aggregation: DefaultMillisecondsDistribution,
  58. }
  59. // Purposely reuses the count from `ServerLatency`, tagging
  60. // with method and status to result in ServerCompletedRpcs.
  61. ServerCompletedRPCsView = &view.View{
  62. Name: "grpc.io/server/completed_rpcs",
  63. Description: "Count of RPCs by method and status.",
  64. TagKeys: []tag.Key{KeyServerMethod, KeyServerStatus},
  65. Measure: ServerLatency,
  66. Aggregation: view.Count(),
  67. }
  68. ServerStartedRPCsView = &view.View{
  69. Measure: ServerStartedRPCs,
  70. Name: "grpc.io/server/started_rpcs",
  71. Description: "Number of started server RPCs.",
  72. TagKeys: []tag.Key{KeyServerMethod},
  73. Aggregation: view.Count(),
  74. }
  75. ServerReceivedMessagesPerRPCView = &view.View{
  76. Name: "grpc.io/server/received_messages_per_rpc",
  77. Description: "Distribution of messages received count per RPC, by method.",
  78. TagKeys: []tag.Key{KeyServerMethod},
  79. Measure: ServerReceivedMessagesPerRPC,
  80. Aggregation: DefaultMessageCountDistribution,
  81. }
  82. ServerSentMessagesPerRPCView = &view.View{
  83. Name: "grpc.io/server/sent_messages_per_rpc",
  84. Description: "Distribution of messages sent count per RPC, by method.",
  85. TagKeys: []tag.Key{KeyServerMethod},
  86. Measure: ServerSentMessagesPerRPC,
  87. Aggregation: DefaultMessageCountDistribution,
  88. }
  89. )
  90. // DefaultServerViews are the default server views provided by this package.
  91. var DefaultServerViews = []*view.View{
  92. ServerReceivedBytesPerRPCView,
  93. ServerSentBytesPerRPCView,
  94. ServerLatencyView,
  95. ServerCompletedRPCsView,
  96. }