-
Notifications
You must be signed in to change notification settings - Fork 2
/
cluster-top-local.go
53 lines (36 loc) · 1.02 KB
/
cluster-top-local.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
47
48
49
50
51
52
53
package main
import (
"flag"
"github.com/patwie/cluster-top/proc"
"time"
)
// hash map of all processes
var work_processes map[int]*proc.Process
var clus Cluster
func main() {
showTimePtr := flag.Bool("t", false, "show time of events")
flag.Parse()
work_processes = make(map[int]*proc.Process)
// load ports and ip-address
cfg := LoadConfig()
node := Node{}
InitNode(&node)
clus.Nodes = append(clus.Nodes, node)
cpu_tick_prev := int64(0)
cpu_tick_cur := int64(0)
cores := proc.NumberCPUCores()
for {
// reset most processes
proc.MarkDirtyProcessList(work_processes)
cpu_tick_cur = proc.CpuTick()
proc.UpdateProcessList(work_processes)
clus.Nodes[0].Cpu.Update()
factor := float32(cpu_tick_cur-cpu_tick_prev) / float32(cores) / 100.
clus.Nodes[0].Processes = GetProcesses(work_processes, factor, cfg.MaxDisplay)
FetchMemory(&clus.Nodes[0].Memory)
clus.Nodes[0].Time = time.Now()
clus.Print(*showTimePtr)
cpu_tick_prev = cpu_tick_cur
time.Sleep(time.Duration(cfg.Tick) * time.Second)
}
}