Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Fix cpu usage percents panic
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Dec 6, 2018
1 parent b166e61 commit 1aa5eea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/widgets/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ func (self *CPU) update() {
if err != nil {
log.Printf("failed to get CPU usage percents from gopsutil: %v. self.interval: %v. percpu: %v", err, self.interval, true)
}
if len(percents) != self.Count {
if len(percents) == self.Count {
for i, percent := range percents {
k := fmt.Sprintf(self.formatString, i)
self.Data[k] = append(self.Data[k], percent)
self.Labels[k] = fmt.Sprintf("%3.0f%%", percent)
}
} else {
log.Printf("error: number of CPU usage percents from gopsutil doesn't match CPU count. percents: %v. self.Count: %v", percents, self.Count)
}
for i := 0; i < self.Count; i++ {
k := fmt.Sprintf(self.formatString, i)
self.Data[k] = append(self.Data[k], percents[i])
self.Labels[k] = fmt.Sprintf("%3.0f%%", percents[i])
}
}()
}
}

0 comments on commit 1aa5eea

Please sign in to comment.