+ stats: GetTopData()
This commit is contained in:
parent
4165688f25
commit
418baa608f
|
@ -42,6 +42,9 @@ type Stats interface {
|
|||
// Update counters
|
||||
Update(e Entry)
|
||||
|
||||
// Get IP addresses of the clients with the most number of requests
|
||||
GetTopClientsIP(limit uint) []string
|
||||
|
||||
// WriteDiskConfig - write configuration
|
||||
WriteDiskConfig(dc *DiskConfig)
|
||||
}
|
||||
|
|
|
@ -75,6 +75,9 @@ func TestStats(t *testing.T) {
|
|||
assert.True(t, d["num_replaced_parental"].(uint64) == 0)
|
||||
assert.True(t, d["avg_processing_time"].(float64) == 0.123456)
|
||||
|
||||
topClients := s.GetTopClientsIP(2)
|
||||
assert.True(t, topClients[0] == "127.0.0.1")
|
||||
|
||||
s.clear()
|
||||
s.Close()
|
||||
os.Remove(conf.Filename)
|
||||
|
|
|
@ -697,3 +697,25 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} {
|
|||
|
||||
return d
|
||||
}
|
||||
|
||||
func (s *statsCtx) GetTopClientsIP(limit uint) []string {
|
||||
lastID := s.conf.UnitID()
|
||||
units := s.loadUnits(lastID)
|
||||
if units == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// top clients
|
||||
m := map[string]uint64{}
|
||||
for _, u := range units {
|
||||
for _, it := range u.Clients {
|
||||
m[it.Name] += it.Count
|
||||
}
|
||||
}
|
||||
a := convertMapToArray(m, int(limit))
|
||||
d := []string{}
|
||||
for _, it := range a {
|
||||
d = append(d, it.Name)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue