-
Notifications
You must be signed in to change notification settings - Fork 0
/
top.go
46 lines (35 loc) · 911 Bytes
/
top.go
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
43
44
45
46
package main
import (
"fmt"
"time"
"github.com/monicasarbu/gotop/cpu"
"github.com/monicasarbu/gotop/load"
"github.com/monicasarbu/gotop/mem"
"github.com/monicasarbu/gotop/proc"
)
func main() {
l, _ := load.Load()
fmt.Printf("Load: %.2f %.2f %.2f\n", l.Load1, l.Load5, l.Load15)
stat2, _ := cpu.Cpu_times_percent(1 * time.Second)
fmt.Printf("%%Cpu: %s\n", stat2.String())
stat2, _ = cpu.Cpu_times_percent(0)
time.Sleep(1 * time.Second)
stat2, _ = cpu.Cpu_times_percent(0)
fmt.Printf("Cpu: %s\n", stat2.String())
m, err := mem.Virtual_memory()
if err != nil {
fmt.Printf("ERROR: %v\n", err)
} else {
fmt.Printf("kB Mem: %s\n", m.String())
}
fmt.Printf("Pids: %v\n", proc.Pids())
pids := proc.Pids()
for _, pid := range pids {
process, err := proc.GetProcess(pid)
if err != nil {
fmt.Printf("ERROR: %v\n", err)
continue
}
fmt.Printf("%s\n", process.String())
}
}