summaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-03-09 00:27:46 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2018-03-09 00:27:46 -0800
commit02219b68894fbd268b83cd1fb2864f444e4d75f7 (patch)
treec1e12d73c88b2da7e84f381d27dddc1d1870edd2 /widgets
parent479491298ea80dd88e00cfaa6bfb0132a879828d (diff)
Added rate; closes #5
Diffstat (limited to 'widgets')
-rw-r--r--widgets/cpu.go6
-rw-r--r--widgets/mem.go4
2 files changed, 5 insertions, 5 deletions
diff --git a/widgets/cpu.go b/widgets/cpu.go
index cc98bf8..82c097c 100644
--- a/widgets/cpu.go
+++ b/widgets/cpu.go
@@ -14,12 +14,12 @@ type CPU struct {
interval time.Duration
}
-func NewCPU() *CPU {
+func NewCPU(interval time.Duration) *CPU {
count, _ := psCPU.Counts(false)
c := &CPU{
LineGraph: ui.NewLineGraph(),
count: count,
- interval: time.Second,
+ interval: interval,
}
c.Label = "CPU Usage"
for i := 0; i < c.count; i++ {
@@ -41,7 +41,7 @@ func NewCPU() *CPU {
func (c *CPU) update() {
// psutil calculates the CPU usage over a 1 second interval, therefore it blocks for 1 second
// `true` makes it so psutil doesn't group CPU usage percentages
- percent, _ := psCPU.Percent(time.Second, true)
+ percent, _ := psCPU.Percent(c.interval, true)
for i := 0; i < c.count; i++ {
key := "CPU" + strconv.Itoa(i+1)
c.Data[key] = append(c.Data[key], percent[i])
diff --git a/widgets/mem.go b/widgets/mem.go
index 06a885c..70bf9ae 100644
--- a/widgets/mem.go
+++ b/widgets/mem.go
@@ -12,10 +12,10 @@ type Mem struct {
interval time.Duration
}
-func NewMem() *Mem {
+func NewMem(interval time.Duration) *Mem {
m := &Mem{
LineGraph: ui.NewLineGraph(),
- interval: time.Second,
+ interval: interval,
}
m.Label = "Memory Usage"
m.Data["Main"] = []float64{0}