l7.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package l7
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. type Protocol uint8
  7. const (
  8. ProtocolHTTP Protocol = 1
  9. ProtocolPostgres Protocol = 2
  10. ProtocolRedis Protocol = 3
  11. ProtocolMemcached Protocol = 4
  12. ProtocolMysql Protocol = 5
  13. ProtocolMongo Protocol = 6
  14. ProtocolKafka Protocol = 7
  15. ProtocolCassandra Protocol = 8
  16. ProtocolRabbitmq Protocol = 9
  17. ProtocolNats Protocol = 10
  18. ProtocolHTTP2 Protocol = 11
  19. ProtocolDubbo2 Protocol = 12
  20. ProtocolTrace Protocol = 200
  21. )
  22. func (p Protocol) String() string {
  23. switch p {
  24. case ProtocolHTTP:
  25. return "HTTP"
  26. case ProtocolPostgres:
  27. return "Postgres"
  28. case ProtocolRedis:
  29. return "Redis"
  30. case ProtocolMemcached:
  31. return "Memcached"
  32. case ProtocolMysql:
  33. return "Mysql"
  34. case ProtocolMongo:
  35. return "Mongo"
  36. case ProtocolKafka:
  37. return "Kafka"
  38. case ProtocolCassandra:
  39. return "Cassandra"
  40. case ProtocolRabbitmq:
  41. return "Rabbitmq"
  42. case ProtocolNats:
  43. return "NATS"
  44. case ProtocolHTTP2:
  45. return "HTTP2"
  46. case ProtocolDubbo2:
  47. return "Dubbo2"
  48. case ProtocolTrace:
  49. return "TRACE"
  50. }
  51. return "UNKNOWN:" + strconv.Itoa(int(p))
  52. }
  53. type Method uint8
  54. const (
  55. MethodUnknown Method = 0
  56. MethodProduce Method = 1
  57. MethodConsume Method = 2
  58. MethodStatementPrepare Method = 3
  59. MethodStatementClose Method = 4
  60. MethodHttp2ClientFrames Method = 5
  61. MethodHttp2ServerFrames Method = 6
  62. )
  63. func (m Method) String() string {
  64. switch m {
  65. case MethodUnknown:
  66. return "unknown"
  67. case MethodProduce:
  68. return "produce"
  69. case MethodConsume:
  70. return "consume"
  71. case MethodStatementPrepare:
  72. return "statement_prepare"
  73. case MethodStatementClose:
  74. return "statement_close"
  75. case MethodHttp2ClientFrames:
  76. return "http2_client_frames"
  77. case MethodHttp2ServerFrames:
  78. return "http2_server_frames"
  79. }
  80. return "UNKNOWN:" + strconv.Itoa(int(m))
  81. }
  82. type Status int
  83. const (
  84. StatusUnknown Status = 0
  85. StatusOk Status = 200
  86. StatusFailed Status = 500
  87. )
  88. func (s Status) String() string {
  89. switch s {
  90. case StatusUnknown:
  91. return "unknown"
  92. case StatusOk:
  93. return "ok"
  94. case StatusFailed:
  95. return "failed"
  96. }
  97. return strconv.Itoa(int(s))
  98. }
  99. func (s Status) Http() string {
  100. return strconv.Itoa(int(s))
  101. }
  102. func (s Status) Error() bool {
  103. return s == StatusFailed
  104. }
  105. type RequestData struct {
  106. Protocol Protocol
  107. Status Status
  108. Duration time.Duration
  109. Method Method
  110. StatementId uint32
  111. Payload []byte
  112. TraceId uint64
  113. TraceStart uint32
  114. TraceEnd uint32
  115. }