-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
75 lines (68 loc) · 1.81 KB
/
main.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
package main
import (
"flag"
"fmt"
"termiboard/cpu"
"termiboard/memory"
"termiboard/network"
"termiboard/utils"
)
var (
// Provisioned by ldflags
version string
buildDate string
commit string
)
var versionString = fmt.Sprintf("v1.0 tag: %s, date: %s, commit: %s", version, buildDate, commit)
var (
showCPUInfo *bool
showCPUUsage *bool
showRAM *bool
showDisk *bool
showLocalIP *bool
showPublicIP *bool
showAll *bool
show5TopRAM *bool
verbose *bool
)
func main() {
//init flags
showCPUInfo = flag.Bool("cpu-info", false, "Show CPU information")
showCPUUsage = flag.Bool("cpu-usage", false, "Show CPU usage")
showRAM = flag.Bool("ram", false, "Show RAM usage")
showDisk = flag.Bool("disk", false, "Show disk usage")
showLocalIP = flag.Bool("local-ip", false, "Show local IP address")
showPublicIP = flag.Bool("public-ip", false, "Show public IP address")
show5TopRAM = flag.Bool("top5-ram", false, "Show top 5 process that consume the most memory")
showAll = flag.Bool("all", false, "Show all stats")
verbose = flag.Bool("verbose", false, "Prints the error in detail")
flag.Parse()
if flag.NFlag() == 0 {
*showAll = true
}
if *verbose {
toggleVerbose()
}
var functionsWithConditions = []struct {
condition bool
function func()
}{
{true, utils.PrintBanner},
{true, func() { utils.StandardPrinter(utils.WarningYellowColor, versionString) }},
{*showCPUInfo, cpu.GetCpuInfo},
{*showCPUUsage, cpu.GetCpuUsage},
{*showRAM, memory.GetRamUsage},
{*showDisk, memory.GetDiskUsage},
{*showLocalIP, network.GetLocalIPAddress},
{*showPublicIP, network.GetPublicIPAddress},
{*show5TopRAM, memory.GetTopProcesses},
}
for _, pair := range functionsWithConditions {
if *showAll || pair.condition {
pair.function()
}
}
}
func toggleVerbose() {
utils.Verbose = true
}