- 内存网络硬盘 github.com/shirou/gopsutil/mem
v, _ := mem.VirtualMemory()
v.Total 总内存字节
v.Free 未使用字节
v.Used 已使用内存字节
v.UsedPercent 49.0000 百分比
c, _ := cpu.Counts(true) 逻辑核心数 8
c, _ := cpu.Counts(false) 物理核心数 4
c, _ := cpu.Percent(2*time.Second,false) 2秒内cpu使用率 8.22222是浮点数
c, _ := cpu.Info() 返回切片信息
c[0].ModelName cpu型号 c[0].Mhz 频率
c, _ := disk.Usage("C:") 硬盘信息
{"path":"C:","fstype":"","total":511818330112,"free":430375731200,"used":8144259
8912,"usedPercent":15.912403702731417,"inodesTotal":0,"inodesUsed":0,"inodesFree
":0,"inodesUsedPercent":0}
c, _ := disk.Partitions(false) 返回驱动信息
[{"device":"C:","mountpoint":"C:","fstype":"NTFS","opts":"rw.compress"} {"device
":"D:","mountpoint":"D:","fstype":"exFAT","opts":"rw"}]
c, _ := host.BootTime() 开机时间
c, _ := host.KernelVersion() 内核版本
c,_ := host.Info()
{"hostname":"XiaoxinAir14","uptime":478717,"bootTime":1601358418,"procs":232,"os
":"windows","platform":"Microsoft Windows 10 Pro","platformFamily":"Standalone W
orkstation","platformVersion":"10.0.19041 Build 19041","kernelVersion":"10.0.190
41 Build 19041","kernelArch":"x86_64","virtualizationSystem":"","virtualizationR
ole":"","hostid":"5ae3c077-b57f-449a-8fe5-84f532b7bc0a"}
a,b,c, _ := host.PlatformInformation()
fmt.Println(a,"|",b,"|",c) Microsoft Windows 10 Pro | Standalone Workstation | 10.0.19041 Build 19041
c,_ := net.IOCounters(true) 网络信息
//获取cpu信息
func getCpuInfo() {
cpuInfos, err := cpu.Info()
if err != nil {
fmt.Printf("get cpu info failed, err:%v", err)
}
for _, ci := range cpuInfos {
fmt.Println(ci)
}
percent, _ := cpu.Percent(time.Second, false)
fmt.Printf("cpu percent:%v\n", percent)
}
//获取硬盘信息 github.com/shirou/gopsutil/disk
func getDiskInfo() {
parts, err := disk.Partitions(true)
if err != nil {
fmt.Printf("get Partitions failed, err:%v\n", err)
return
}
for _, part := range parts {
fmt.Printf("part:%v\n", part.String())
diskInfo, _ := disk.Usage(part.Mountpoint)
fmt.Printf("disk info:used:%v free:%v\n", diskInfo.UsedPercent, diskInfo.Free)
}
ioStat, _ := disk.IOCounters()
for k, v := range ioStat {
fmt.Printf("%v:%v\n", k, v)
}
}
- 电池 “github.com/distatus/battery”
bt, _ := battery.GetAll() for _, battery := range bt { fmt.Printf("当前电池容量: %d mWh, ", int64(battery.Current)) fmt.Printf("全部电池容量: %d mWh, ", int64(battery.Full)) fmt.Printf("设计电池容量: %d mWh, ", int64(battery.Design)) fmt.Printf("充电率: %d mW, ", int64(battery.ChargeRate)) fmt.Printf("电压: %.2f V, ", battery.Voltage) fmt.Printf("设计电压: %.2f V,", battery.DesignVoltage) fmt.Printf("剩余电量: %.2f %%\n", battery.Current/battery.Full*100) }
作者:Yoby 创建时间:2020-10-04 22:34
更新时间:2024-12-05 13:26
更新时间:2024-12-05 13:26