metrics.go 1.3 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(name string, proxyType string) {}
  26. func (noopServerMetrics) CloseProxy(name string, proxyType string) {}
  27. func (noopServerMetrics) OpenConnection(name string, proxyType string) {}
  28. func (noopServerMetrics) CloseConnection(name string, proxyType string) {}
  29. func (noopServerMetrics) AddTrafficIn(name string, proxyType string, trafficBytes int64) {}
  30. func (noopServerMetrics) AddTrafficOut(name string, proxyType string, trafficBytes int64) {}