Use generic TimedStore for stats storage
This commit is contained in:
parent
8d2f81e73f
commit
c72445a698
@ -39,14 +39,19 @@ func (self *containerStorage) AddStats(stats *info.ContainerStats) error {
|
|||||||
defer self.lock.Unlock()
|
defer self.lock.Unlock()
|
||||||
|
|
||||||
// Add the stat to storage.
|
// Add the stat to storage.
|
||||||
self.recentStats.Add(stats)
|
self.recentStats.Add(stats.Timestamp, stats)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *containerStorage) RecentStats(start, end time.Time, maxStats int) ([]*info.ContainerStats, error) {
|
func (self *containerStorage) RecentStats(start, end time.Time, maxStats int) ([]*info.ContainerStats, error) {
|
||||||
self.lock.RLock()
|
self.lock.RLock()
|
||||||
defer self.lock.RUnlock()
|
defer self.lock.RUnlock()
|
||||||
return self.recentStats.InTimeRange(start, end, maxStats), nil
|
result := self.recentStats.InTimeRange(start, end, maxStats)
|
||||||
|
converted := make([]*info.ContainerStats, len(result))
|
||||||
|
for i, el := range result {
|
||||||
|
converted[i] = el.(*info.ContainerStats)
|
||||||
|
}
|
||||||
|
return converted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContainerStore(ref info.ContainerReference, maxAge time.Duration) *containerStorage {
|
func newContainerStore(ref info.ContainerReference, maxAge time.Duration) *containerStorage {
|
||||||
|
Loading…
Reference in New Issue
Block a user