metrics.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package metrics
  2. import (
  3. "sync"
  4. )
  5. type ServerMetrics interface {
  6. NewClient()
  7. CloseClient()
  8. NewProxy(name string, proxyType string)
  9. CloseProxy(name string, proxyType string)
  10. OpenConnection(name string, proxyType string)
  11. CloseConnection(name string, proxyType string)
  12. AddTrafficIn(name string, proxyType string, trafficBytes int64)
  13. AddTrafficOut(name string, proxyType string, trafficBytes int64)
  14. }
  15. var Server ServerMetrics = noopServerMetrics{}
  16. var registerMetrics sync.Once
  17. func Register(m ServerMetrics) {
  18. registerMetrics.Do(func() {
  19. Server = m
  20. })
  21. }
  22. type noopServerMetrics struct{}
  23. func (noopServerMetrics) NewClient() {}
  24. func (noopServerMetrics) CloseClient() {}
  25. func (noopServerMetrics) NewProxy(string, string) {}
  26. func (noopServerMetrics) CloseProxy(string, string) {}
  27. func (noopServerMetrics) OpenConnection(string, string) {}
  28. func (noopServerMetrics) CloseConnection(string, string) {}
  29. func (noopServerMetrics) AddTrafficIn(string, string, int64) {}
  30. func (noopServerMetrics) AddTrafficOut(string, string, int64) {}