Use metrics

This commit is contained in:
Daniel
2021-01-28 17:45:52 +01:00
parent ee9ee3dc68
commit c9b89ef2ea
13 changed files with 289 additions and 6 deletions

View File

@@ -55,3 +55,24 @@ func (cs *connectionStore) clone() map[string]*Connection {
}
return m
}
func (cs *connectionStore) len() int {
cs.rw.RLock()
defer cs.rw.RUnlock()
return len(cs.items)
}
func (cs *connectionStore) active() int {
// Clone and count all active connections.
var cnt int
for _, conn := range cs.clone() {
conn.Lock()
if conn.Ended != 0 {
cnt++
}
conn.Unlock()
}
return cnt
}