Skip to content

Commit

Permalink
Handle dynamic housekeeping in derived stats.
Browse files Browse the repository at this point in the history
Use timestamps instead of sample counts for generating summary.
  • Loading branch information
rjnagal committed Feb 27, 2015
1 parent ed38123 commit e3e6552
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions summary/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ func (s *StatsSummary) AddSample(stat info.ContainerStats) error {
s.secondSamples = append(s.secondSamples, &sample)
s.updateLatestUsage()
// TODO(jnagal): Use 'available' to avoid unnecessary computation.
if len(s.secondSamples) == 60 {
// Make a minute stat.
numSamples := len(s.secondSamples)
elapsed := time.Nanosecond
if numSamples > 1 {
start := s.secondSamples[0].Timestamp
end := s.secondSamples[numSamples-1].Timestamp
elapsed = end.Sub(start)
}
if elapsed > 60*time.Second {
// Make a minute sample. This works with dynamic housekeeping as long
// as we keep max dynamic houskeeping period close to a minute.
minuteSample := GetMinutePercentiles(s.secondSamples)
// clear seconds samples.
s.secondSamples = s.secondSamples[:0]
// Clear seconds samples. Keep the latest sample for continuity.
// Copying and resizing helps avoid slice re-allocation.
s.secondSamples[0] = s.secondSamples[numSamples-1]
s.secondSamples = s.secondSamples[:1]
s.minuteSamples.Add(minuteSample)
err := s.updateDerivedStats()
if err != nil {
Expand Down

0 comments on commit e3e6552

Please sign in to comment.