server_metrics.go 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. 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)
  28. )
  29. // TODO(acetechnologist): This is temporary and will need to be replaced by a
  30. // mechanism to load these defaults from a common repository/config shared by
  31. // all supported languages. Likely a serialized protobuf of these defaults.
  32. // Predefined views may be registered to collect data for the above measures.
  33. // As always, you may also define your own custom views over measures collected by this
  34. // package. These are declared as a convenience only; none are registered by
  35. // default.
  36. var (
  37. ServerReceivedBytesPerRPCView = &view.View{
  38. Name: "grpc.io/server/received_bytes_per_rpc",
  39. Description: "Distribution of received bytes per RPC, by method.",
  40. Measure: ServerReceivedBytesPerRPC,
  41. TagKeys: []tag.Key{KeyServerMethod},
  42. Aggregation: DefaultBytesDistribution,
  43. }
  44. ServerSentBytesPerRPCView = &view.View{
  45. Name: "grpc.io/server/sent_bytes_per_rpc",
  46. Description: "Distribution of total sent bytes per RPC, by method.",
  47. Measure: ServerSentBytesPerRPC,
  48. TagKeys: []tag.Key{KeyServerMethod},
  49. Aggregation: DefaultBytesDistribution,
  50. }
  51. ServerLatencyView = &view.View{
  52. Name: "grpc.io/server/server_latency",
  53. Description: "Distribution of server latency in milliseconds, by method.",
  54. TagKeys: []tag.Key{KeyServerMethod},
  55. Measure: ServerLatency,
  56. Aggregation: DefaultMillisecondsDistribution,
  57. }
  58. ServerCompletedRPCsView = &view.View{
  59. Name: "grpc.io/server/completed_rpcs",
  60. Description: "Count of RPCs by method and status.",
  61. TagKeys: []tag.Key{KeyServerMethod, KeyServerStatus},
  62. Measure: ServerLatency,
  63. Aggregation: view.Count(),
  64. }
  65. ServerReceivedMessagesPerRPCView = &view.View{
  66. Name: "grpc.io/server/received_messages_per_rpc",
  67. Description: "Distribution of messages received count per RPC, by method.",
  68. TagKeys: []tag.Key{KeyServerMethod},
  69. Measure: ServerReceivedMessagesPerRPC,
  70. Aggregation: DefaultMessageCountDistribution,
  71. }
  72. ServerSentMessagesPerRPCView = &view.View{
  73. Name: "grpc.io/server/sent_messages_per_rpc",
  74. Description: "Distribution of messages sent count per RPC, by method.",
  75. TagKeys: []tag.Key{KeyServerMethod},
  76. Measure: ServerSentMessagesPerRPC,
  77. Aggregation: DefaultMessageCountDistribution,
  78. }
  79. )
  80. // DefaultServerViews are the default server views provided by this package.
  81. var DefaultServerViews = []*view.View{
  82. ServerReceivedBytesPerRPCView,
  83. ServerSentBytesPerRPCView,
  84. ServerLatencyView,
  85. ServerCompletedRPCsView,
  86. }