Get system info
This commit is contained in:
parent
141141b3f1
commit
4b9bb18aa0
@ -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)
|
|
||||||
}
|
|
63
cmd/playground/main.go
Normal file
63
cmd/playground/main.go
Normal file
@ -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)
|
||||||
|
}
|
7
go.mod
7
go.mod
@ -1,3 +1,8 @@
|
|||||||
module github.com/naiba/nbackup
|
module github.com/p14yground/nezha
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/shirou/gopsutil v2.19.11+incompatible
|
||||||
|
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
|
||||||
|
)
|
||||||
|
5
go.sum
Normal file
5
go.sum
Normal file
@ -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=
|
Loading…
Reference in New Issue
Block a user