blob: 5b80c4d8c6cd07f9443d23c4656dc42e8ca4651a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package widgets
import (
"time"
ui "github.com/cjbassi/termui"
psMem "github.com/shirou/gopsutil/mem"
)
type Mem struct {
*ui.LineGraph
interval time.Duration
}
func NewMem(interval time.Duration, zoom int) *Mem {
self := &Mem{
LineGraph: ui.NewLineGraph(),
interval: interval,
}
self.Label = "Memory Usage"
self.Zoom = zoom
self.Data["Main"] = []float64{0}
self.Data["Swap"] = []float64{0}
self.update()
ticker := time.NewTicker(self.interval)
go func() {
for range ticker.C {
self.update()
}
}()
return self
}
func (self *Mem) update() {
main, _ := psMem.VirtualMemory()
swap, _ := psMem.SwapMemory()
self.Data["Main"] = append(self.Data["Main"], main.UsedPercent)
self.Data["Swap"] = append(self.Data["Swap"], swap.UsedPercent)
}
|