stats.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. *
  3. * Copyright 2016 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package stats is for collecting and reporting various network and RPC stats.
  19. // This package is for monitoring purpose only. All fields are read-only.
  20. // All APIs are experimental.
  21. package stats // import "google.golang.org/grpc/stats"
  22. import (
  23. "net"
  24. "time"
  25. )
  26. // RPCStats contains stats information about RPCs.
  27. type RPCStats interface {
  28. isRPCStats()
  29. // IsClient returns true if this RPCStats is from client side.
  30. IsClient() bool
  31. }
  32. // Begin contains stats when an RPC begins.
  33. // FailFast is only valid if this Begin is from client side.
  34. type Begin struct {
  35. // Client is true if this Begin is from client side.
  36. Client bool
  37. // BeginTime is the time when the RPC begins.
  38. BeginTime time.Time
  39. // FailFast indicates if this RPC is failfast.
  40. FailFast bool
  41. }
  42. // IsClient indicates if the stats information is from client side.
  43. func (s *Begin) IsClient() bool { return s.Client }
  44. func (s *Begin) isRPCStats() {}
  45. // InPayload contains the information for an incoming payload.
  46. type InPayload struct {
  47. // Client is true if this InPayload is from client side.
  48. Client bool
  49. // Payload is the payload with original type.
  50. Payload interface{}
  51. // Data is the serialized message payload.
  52. Data []byte
  53. // Length is the length of uncompressed data.
  54. Length int
  55. // WireLength is the length of data on wire (compressed, signed, encrypted).
  56. WireLength int
  57. // RecvTime is the time when the payload is received.
  58. RecvTime time.Time
  59. }
  60. // IsClient indicates if the stats information is from client side.
  61. func (s *InPayload) IsClient() bool { return s.Client }
  62. func (s *InPayload) isRPCStats() {}
  63. // InHeader contains stats when a header is received.
  64. type InHeader struct {
  65. // Client is true if this InHeader is from client side.
  66. Client bool
  67. // WireLength is the wire length of header.
  68. WireLength int
  69. // The following fields are valid only if Client is false.
  70. // FullMethod is the full RPC method string, i.e., /package.service/method.
  71. FullMethod string
  72. // RemoteAddr is the remote address of the corresponding connection.
  73. RemoteAddr net.Addr
  74. // LocalAddr is the local address of the corresponding connection.
  75. LocalAddr net.Addr
  76. // Compression is the compression algorithm used for the RPC.
  77. Compression string
  78. }
  79. // IsClient indicates if the stats information is from client side.
  80. func (s *InHeader) IsClient() bool { return s.Client }
  81. func (s *InHeader) isRPCStats() {}
  82. // InTrailer contains stats when a trailer is received.
  83. type InTrailer struct {
  84. // Client is true if this InTrailer is from client side.
  85. Client bool
  86. // WireLength is the wire length of trailer.
  87. WireLength int
  88. }
  89. // IsClient indicates if the stats information is from client side.
  90. func (s *InTrailer) IsClient() bool { return s.Client }
  91. func (s *InTrailer) isRPCStats() {}
  92. // OutPayload contains the information for an outgoing payload.
  93. type OutPayload struct {
  94. // Client is true if this OutPayload is from client side.
  95. Client bool
  96. // Payload is the payload with original type.
  97. Payload interface{}
  98. // Data is the serialized message payload.
  99. Data []byte
  100. // Length is the length of uncompressed data.
  101. Length int
  102. // WireLength is the length of data on wire (compressed, signed, encrypted).
  103. WireLength int
  104. // SentTime is the time when the payload is sent.
  105. SentTime time.Time
  106. }
  107. // IsClient indicates if this stats information is from client side.
  108. func (s *OutPayload) IsClient() bool { return s.Client }
  109. func (s *OutPayload) isRPCStats() {}
  110. // OutHeader contains stats when a header is sent.
  111. type OutHeader struct {
  112. // Client is true if this OutHeader is from client side.
  113. Client bool
  114. // WireLength is the wire length of header.
  115. WireLength int
  116. // The following fields are valid only if Client is true.
  117. // FullMethod is the full RPC method string, i.e., /package.service/method.
  118. FullMethod string
  119. // RemoteAddr is the remote address of the corresponding connection.
  120. RemoteAddr net.Addr
  121. // LocalAddr is the local address of the corresponding connection.
  122. LocalAddr net.Addr
  123. // Compression is the compression algorithm used for the RPC.
  124. Compression string
  125. }
  126. // IsClient indicates if this stats information is from client side.
  127. func (s *OutHeader) IsClient() bool { return s.Client }
  128. func (s *OutHeader) isRPCStats() {}
  129. // OutTrailer contains stats when a trailer is sent.
  130. type OutTrailer struct {
  131. // Client is true if this OutTrailer is from client side.
  132. Client bool
  133. // WireLength is the wire length of trailer.
  134. WireLength int
  135. }
  136. // IsClient indicates if this stats information is from client side.
  137. func (s *OutTrailer) IsClient() bool { return s.Client }
  138. func (s *OutTrailer) isRPCStats() {}
  139. // End contains stats when an RPC ends.
  140. type End struct {
  141. // Client is true if this End is from client side.
  142. Client bool
  143. // EndTime is the time when the RPC ends.
  144. EndTime time.Time
  145. // Error is the error just happened. It implements status.Status if non-nil.
  146. Error error
  147. }
  148. // IsClient indicates if this is from client side.
  149. func (s *End) IsClient() bool { return s.Client }
  150. func (s *End) isRPCStats() {}
  151. // ConnStats contains stats information about connections.
  152. type ConnStats interface {
  153. isConnStats()
  154. // IsClient returns true if this ConnStats is from client side.
  155. IsClient() bool
  156. }
  157. // ConnBegin contains the stats of a connection when it is established.
  158. type ConnBegin struct {
  159. // Client is true if this ConnBegin is from client side.
  160. Client bool
  161. }
  162. // IsClient indicates if this is from client side.
  163. func (s *ConnBegin) IsClient() bool { return s.Client }
  164. func (s *ConnBegin) isConnStats() {}
  165. // ConnEnd contains the stats of a connection when it ends.
  166. type ConnEnd struct {
  167. // Client is true if this ConnEnd is from client side.
  168. Client bool
  169. }
  170. // IsClient indicates if this is from client side.
  171. func (s *ConnEnd) IsClient() bool { return s.Client }
  172. func (s *ConnEnd) isConnStats() {}