-
Notifications
You must be signed in to change notification settings - Fork 0
/
synopsys.go
87 lines (76 loc) · 1.55 KB
/
synopsys.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"log"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/bioe007/synopsys/cpu"
"github.com/bioe007/synopsys/disk"
"github.com/bioe007/synopsys/load"
"github.com/bioe007/synopsys/memory"
"github.com/bioe007/synopsys/uptime"
)
// main stuff getting done
func main() {
// Argument(s) is only an int to agjust frequency
var num_seconds int
var err error
if len(os.Args) < 2 {
num_seconds = 1
} else {
num_seconds, err = strconv.Atoi(os.Args[1])
if err != nil {
usage()
}
}
ticker := time.NewTicker(time.Duration(num_seconds) * time.Second)
go func() {
c := new(cpu.CpuInfo)
for ; ; <-ticker.C {
c, err = cpu.CPUStats(c)
if err != nil {
log.Fatal(err)
}
m, err := memory.Getmeminfo()
if err != nil {
log.Fatal(err)
}
ld, err := load.LoadAvg()
if err != nil {
log.Fatal("Load average failure", err)
}
disks, err := disk.DiskStats()
if err != nil {
log.Fatal("disk average failure", err)
}
fmt.Println("Got disks: ", len(disks))
ut, err := uptime.Read_uptime()
if err != nil {
log.Fatal("Unable to read uptime")
}
fmt.Printf(
"up:%s %s cpu:%s\nmem: %s\n",
ut.HoursMinutes(),
ld.InfoPrint(),
c.InfoPrint(4),
m.InfoPrint(),
)
}
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
done := make(chan bool, 1)
// Wait until getting SIGINT or SIGTERM
go func() {
_ = <-sigs
done <- true
}()
<-done
}
func usage() {
fmt.Printf("Usage: %s [<interval>]", os.Args[0])
os.Exit(0)
}