-
Notifications
You must be signed in to change notification settings - Fork 1
/
eznode_stats.go
41 lines (35 loc) · 888 Bytes
/
eznode_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package eznode
import (
"sync/atomic"
)
func (c *Chain) getStats() []ChainNodeStats {
c.mutex.RLock()
nodeStats := make([]ChainNodeStats, 0)
for _, node := range c.nodes {
node.statsMutex.Lock()
nodeStats = append(nodeStats, ChainNodeStats{
Name: node.name,
CurrentHits: node.hits,
TotalHits: atomic.LoadUint64(&node.totalHits),
ResponseStats: node.responseStats,
Limits: node.limit.Count,
Priority: node.priority,
Disabled: node.disabled,
Fails: node.fails,
})
node.statsMutex.Unlock()
}
c.mutex.RUnlock()
return nodeStats
}
// GetStats returns the stats of chains
func (e *EzNode) GetStats() []ChainStats {
chainStats := make([]ChainStats, 0)
for _, chain := range e.chains {
chainStats = append(chainStats, ChainStats{
Id: chain.id,
Nodes: chain.getStats(),
})
}
return chainStats
}