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