diff --git a/cmd/web/main.go b/cmd/dashboard/main.go similarity index 100% rename from cmd/web/main.go rename to cmd/dashboard/main.go diff --git a/cmd/ping/main.go b/cmd/ping/main.go deleted file mode 100644 index 9181662..0000000 --- a/cmd/ping/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "log" - "os/exec" -) - -func main() { - cmd := exec.Command("ping", "qiongbi.net", "-c5") - output, err := cmd.Output() - log.Println("output:", string(output)) - log.Println("err:", err) - - cmd = exec.Command("ping", "qiongbi", "-c5") - output, err = cmd.Output() - log.Println("output:", string(output)) - log.Println("err:", err) -} diff --git a/cmd/playground/main.go b/cmd/playground/main.go new file mode 100644 index 0000000..11faae4 --- /dev/null +++ b/cmd/playground/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "fmt" + "log" + "os/exec" + "strconv" + "time" + + "github.com/shirou/gopsutil/cpu" + "github.com/shirou/gopsutil/disk" + "github.com/shirou/gopsutil/host" + "github.com/shirou/gopsutil/mem" + "github.com/shirou/gopsutil/net" +) + +func main() { + // Host info + hi, _ := host.Info() + fmt.Printf("「HostInfo」 platform:%v platformVersion:%v kernelArch:%v virtualizationSystem:%v\n", hi.OS, hi.PlatformVersion, hi.KernelArch, hi.VirtualizationSystem) + // Memory + mv, _ := mem.VirtualMemory() + ms, _ := mem.SwapMemory() + fmt.Printf("「VirtualMemory」 Total: %v, Free:%v, UsedPercent:%f%%\n", mv.Total, mv.Free, mv.UsedPercent) + fmt.Printf("「SwapMemory」 Total: %v, Free:%v, UsedPercent:%f%%\n", ms.Total, ms.Free, ms.UsedPercent) + // Disk + dparts, _ := disk.Partitions(false) + for _, part := range dparts { + fmt.Printf("「Disk」 %v\n", part) + u, _ := disk.Usage(part.Mountpoint) + fmt.Println("\t" + u.Path + "\t" + strconv.FormatFloat(u.UsedPercent, 'f', 2, 64) + "% full.") + fmt.Println("\t\tTotal: " + strconv.FormatUint(u.Total/1024/1024/1024, 10) + " GiB") + fmt.Println("\t\tFree: " + strconv.FormatUint(u.Free/1024/1024/1024, 10) + " GiB") + fmt.Println("\t\tUsed: " + strconv.FormatUint(u.Used/1024/1024/1024, 10) + " GiB") + } + // CPU + go func() { + cp, _ := cpu.Percent(time.Second*2, false) + ci, _ := cpu.Info() + for i := 0; i < len(ci); i++ { + fmt.Printf("「CPU」 %v core:%v step:%v", ci[i].ModelName, ci[i].Cores, ci[i].Stepping) + } + fmt.Printf(" percentIn2sec:%v%%\n", cp[0]) + }() + // Network + nc, _ := net.IOCounters(true) + for _, ni := range nc { + fmt.Printf("「Net」%v\n", ni) + } + select {} +} + +func cmdExec() { + cmd := exec.Command("ping", "qiongbi.net", "-c2") + output, err := cmd.Output() + log.Println("output:", string(output)) + log.Println("err:", err) + + cmd = exec.Command("ping", "qiongbi", "-c2") + output, err = cmd.Output() + log.Println("output:", string(output)) + log.Println("err:", err) +} diff --git a/go.mod b/go.mod index bc6360f..0661305 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ -module github.com/naiba/nbackup +module github.com/p14yground/nezha go 1.13 + +require ( + github.com/shirou/gopsutil v2.19.11+incompatible + golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0e2f3f4 --- /dev/null +++ b/go.sum @@ -0,0 +1,5 @@ +github.com/naiba/nbackup v0.0.0-20191201153623-141141b3f112 h1:qC+LR6aVs9ezpNvnGIZz/sqghFTiBG1JczlUliDJYvQ= +github.com/shirou/gopsutil v2.19.11+incompatible h1:lJHR0foqAjI4exXqWsU3DbH7bX1xvdhGdnXTIARA9W4= +github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU= +golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=