stats.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. *
  3. * Copyright 2016, Google Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. // Package stats is for collecting and reporting various network and RPC stats.
  34. // This package is for monitoring purpose only. All fields are read-only.
  35. // All APIs are experimental.
  36. package stats // import "google.golang.org/grpc/stats"
  37. import (
  38. "net"
  39. "time"
  40. )
  41. // RPCStats contains stats information about RPCs.
  42. type RPCStats interface {
  43. isRPCStats()
  44. // IsClient returns true if this RPCStats is from client side.
  45. IsClient() bool
  46. }
  47. // Begin contains stats when an RPC begins.
  48. // FailFast are only valid if Client is true.
  49. type Begin struct {
  50. // Client is true if this Begin is from client side.
  51. Client bool
  52. // BeginTime is the time when the RPC begins.
  53. BeginTime time.Time
  54. // FailFast indicates if this RPC is failfast.
  55. FailFast bool
  56. }
  57. // IsClient indicates if this is from client side.
  58. func (s *Begin) IsClient() bool { return s.Client }
  59. func (s *Begin) isRPCStats() {}
  60. // InPayload contains the information for an incoming payload.
  61. type InPayload struct {
  62. // Client is true if this InPayload is from client side.
  63. Client bool
  64. // Payload is the payload with original type.
  65. Payload interface{}
  66. // Data is the serialized message payload.
  67. Data []byte
  68. // Length is the length of uncompressed data.
  69. Length int
  70. // WireLength is the length of data on wire (compressed, signed, encrypted).
  71. WireLength int
  72. // RecvTime is the time when the payload is received.
  73. RecvTime time.Time
  74. }
  75. // IsClient indicates if this is from client side.
  76. func (s *InPayload) IsClient() bool { return s.Client }
  77. func (s *InPayload) isRPCStats() {}
  78. // InHeader contains stats when a header is received.
  79. // FullMethod, addresses and Compression are only valid if Client is false.
  80. type InHeader struct {
  81. // Client is true if this InHeader is from client side.
  82. Client bool
  83. // WireLength is the wire length of header.
  84. WireLength int
  85. // FullMethod is the full RPC method string, i.e., /package.service/method.
  86. FullMethod string
  87. // RemoteAddr is the remote address of the corresponding connection.
  88. RemoteAddr net.Addr
  89. // LocalAddr is the local address of the corresponding connection.
  90. LocalAddr net.Addr
  91. // Compression is the compression algorithm used for the RPC.
  92. Compression string
  93. }
  94. // IsClient indicates if this is from client side.
  95. func (s *InHeader) IsClient() bool { return s.Client }
  96. func (s *InHeader) isRPCStats() {}
  97. // InTrailer contains stats when a trailer is received.
  98. type InTrailer struct {
  99. // Client is true if this InTrailer is from client side.
  100. Client bool
  101. // WireLength is the wire length of trailer.
  102. WireLength int
  103. }
  104. // IsClient indicates if this is from client side.
  105. func (s *InTrailer) IsClient() bool { return s.Client }
  106. func (s *InTrailer) isRPCStats() {}
  107. // OutPayload contains the information for an outgoing payload.
  108. type OutPayload struct {
  109. // Client is true if this OutPayload is from client side.
  110. Client bool
  111. // Payload is the payload with original type.
  112. Payload interface{}
  113. // Data is the serialized message payload.
  114. Data []byte
  115. // Length is the length of uncompressed data.
  116. Length int
  117. // WireLength is the length of data on wire (compressed, signed, encrypted).
  118. WireLength int
  119. // SentTime is the time when the payload is sent.
  120. SentTime time.Time
  121. }
  122. // IsClient indicates if this is from client side.
  123. func (s *OutPayload) IsClient() bool { return s.Client }
  124. func (s *OutPayload) isRPCStats() {}
  125. // OutHeader contains stats when a header is sent.
  126. // FullMethod, addresses and Compression are only valid if Client is true.
  127. type OutHeader struct {
  128. // Client is true if this OutHeader is from client side.
  129. Client bool
  130. // WireLength is the wire length of header.
  131. WireLength int
  132. // FullMethod is the full RPC method string, i.e., /package.service/method.
  133. FullMethod string
  134. // RemoteAddr is the remote address of the corresponding connection.
  135. RemoteAddr net.Addr
  136. // LocalAddr is the local address of the corresponding connection.
  137. LocalAddr net.Addr
  138. // Compression is the compression algorithm used for the RPC.
  139. Compression string
  140. }
  141. // IsClient indicates if this is from client side.
  142. func (s *OutHeader) IsClient() bool { return s.Client }
  143. func (s *OutHeader) isRPCStats() {}
  144. // OutTrailer contains stats when a trailer is sent.
  145. type OutTrailer struct {
  146. // Client is true if this OutTrailer is from client side.
  147. Client bool
  148. // WireLength is the wire length of trailer.
  149. WireLength int
  150. }
  151. // IsClient indicates if this is from client side.
  152. func (s *OutTrailer) IsClient() bool { return s.Client }
  153. func (s *OutTrailer) isRPCStats() {}
  154. // End contains stats when an RPC ends.
  155. type End struct {
  156. // Client is true if this End is from client side.
  157. Client bool
  158. // EndTime is the time when the RPC ends.
  159. EndTime time.Time
  160. // Error is the error just happened. Its type is gRPC error.
  161. Error error
  162. }
  163. // IsClient indicates if this is from client side.
  164. func (s *End) IsClient() bool { return s.Client }
  165. func (s *End) isRPCStats() {}
  166. // ConnStats contains stats information about connections.
  167. type ConnStats interface {
  168. isConnStats()
  169. // IsClient returns true if this ConnStats is from client side.
  170. IsClient() bool
  171. }
  172. // ConnBegin contains the stats of a connection when it is established.
  173. type ConnBegin struct {
  174. // Client is true if this ConnBegin is from client side.
  175. Client bool
  176. }
  177. // IsClient indicates if this is from client side.
  178. func (s *ConnBegin) IsClient() bool { return s.Client }
  179. func (s *ConnBegin) isConnStats() {}
  180. // ConnEnd contains the stats of a connection when it ends.
  181. type ConnEnd struct {
  182. // Client is true if this ConnEnd is from client side.
  183. Client bool
  184. }
  185. // IsClient indicates if this is from client side.
  186. func (s *ConnEnd) IsClient() bool { return s.Client }
  187. func (s *ConnEnd) isConnStats() {}