Open CHN-STUDENT opened 3 years ago
It's quite hard to reason about this problem as you compare two programs that might not use the same APIs. Especially for the windows task manager that could be using windows kernel primitives directly (as I remember it being able to display some non exported stats in some older issue in (go)psutil), so APIs not accessible to us).
Also I can't reproduce your first screenshot on my win10 VM (an older 10.0.17763.168).
The results for the swap partition in your app look at least quite similar compared to task manager.
About the network traffic, the issue is that the numbers are completely different between 5.28G | 82.91G
and 693.1M | 231.8M
?
@Lomanic hello, lomanic
I mean my computer 's physical memory is 16 GB, however i use gopsutil mem.SwapMemory()
to get size is 18 GB, i guess the 2 GB is pagefile. In task manger memory info page (not in disk partition page,sorry my screenshot is confusing ), it shows the size is 18 GB too = physical + pagefile , i do not know how difference windows's pagefile or linux swap parition, so i think it is wrong result? What do you think?
And the network traffic i think in the windows the result is wrong, My windows uses a lot of traffic, I can not believe the result is real, so i want to know what idea from you ? What do you think?
Swap usage in windows has been introduced by #423. Currently gopsutil uses GetPerformanceInfo()
to get Commit Charge which includes both the physical memory and the page file size. So it is correct to get swap usage from those values. FYI: discussion in Oshi project
However, I found psutil uses GlobalMemoryStatusEx on psutil_virtual_mem to get swap usage . And also, docker uses GlobalMemoryStatusEx which is introduced by this PR made by microsoft. so I think use GlobalMemoryStatusEx is better to get Swap Usage.
And for the Network traffic, could you talk us more detail about
hi @shirou Glad to get your reply, you explan how to calc memory size, i think it is not a issue, Thank you! And network traffic could you tell me how to calc it ? I mean i download a big size file, seems it is smaller than actual value, i want to calc all network traffic when system start on, but i do not know the gopsutil can get this?
2020.12.24 Update:the python version psutil counts network traffic which seems same with gopsutil, so i do not think it is not a issue too.
But the disk space count i have a problem which will need your help.
@shirou @Lomanic And i get other question about disk count in windows, i want to calc all disk space in windows, And my windows include Network Partition (Z:), could you tell me how to distinguish Network Partition or other Disk by using disk.Partitions(false)
Here all my code:
diskList, _ := disk.Partitions(false)
fmt.Println(diskList)
var total uint64 = 0
var used uint64 = 0
for _,d := range diskList {
fsType := strings.ToLower(d.Fstype)
//fmt.Println(d.Fstype)
if strings.Index(fsType, "ext4") < 0 &&
strings.Index(fsType, "ext3") < 0 &&
strings.Index(fsType, "ext2") < 0 &&
strings.Index(fsType, "reiserfs") < 0 &&
strings.Index(fsType, "jfs") < 0 &&
strings.Index(fsType, "btrfs") < 0 &&
strings.Index(fsType, "fuseblk") < 0 &&
strings.Index(fsType, "zfs") < 0 &&
strings.Index(fsType, "simfs") < 0 &&
strings.Index(fsType, "ntfs")< 0 &&
strings.Index(fsType, "fat32") < 0 &&
strings.Index(fsType, "exfat") < 0 &&
strings.Index(fsType, "xfs") < 0 {
continue
} else {
diskUsageOf, _ := disk.Usage(d.Mountpoint)
used += diskUsageOf.Used
total += diskUsageOf.Total
}
}
Describe the bug I want to write a online system monior system, i have use gopsutil as getting info libary, however i found some error in my windows system.
net.IOCounters(true)
, it can work on windows and linux, however i do not think the windows version result is right.mem.SwapMemory()
will get all physical memory + pagefile.sys size.To Reproduce
func trafficCount() { netInfo, err := nnet.IOCounters(true) if err != nil { fmt.Println("Get traffic count error:",err) } var bytesSent uint64 = 0 var bytesRecv uint64 = 0 for _, v := range netInfo { if strings.Index(v.Name,"lo") > -1 || strings.Index(v.Name,"tun") > -1 || strings.Index(v.Name,"docker") > -1 || strings.Index(v.Name,"veth") > -1 || strings.Index(v.Name,"br-") > -1 || strings.Index(v.Name,"vmbr") > -1 || strings.Index(v.Name,"vnet") > -1 || strings.Index(v.Name,"kube") > -1 { continue } bytesSent += v.BytesSent bytesRecv += v.BytesRecv } clientInfo.NetworkIn = bytesRecv clientInfo.NetworkOut = bytesSent }
Expected behavior Do not know how to make them exactly, please help me.
Environment (please complete the following information):
ver
]/etc/os-release
and the result ofuname -a
]sw_vers
anduname -a
freebsd-version -k -r -u
anduname -a
]uname -a
]Additional context Microsoft Windows [Version 10.0.19042.630] go version go1.15.5 windows/amd64 Also my project is open-source,see it on here: https://github.com/CHN-STUDENT/ServerStatus/tree/master/clients/golang/awesomeProject