Merge pull request #103 from Creling/master

fix: correct minor typos in disk usage statistic

Co-authored-by: Creling <43109504+Creling@users.noreply.github.com>
This commit is contained in:
naiba 2021-02-27 17:12:31 +08:00 committed by GitHub
commit 549e1972bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,7 +35,12 @@ func GetHost() *model.Host {
}
mv, _ := mem.VirtualMemory()
ms, _ := mem.SwapMemory()
u, _ := disk.Usage("/")
u, _ := disk.Partitions(false)
var total uint64
for _, dev := range u {
usage, _ := disk.Usage(dev.Mountpoint)
total += usage.Total
}
var ip ipDotSbGeoIP
resp, err := http.Get("https://api-ipv4.ip.sb/geoip")
if err == nil {
@ -54,7 +59,7 @@ func GetHost() *model.Host {
PlatformVersion: hi.PlatformVersion,
CPU: cpus,
MemTotal: mv.Total,
DiskTotal: u.Total,
DiskTotal: total,
SwapTotal: ms.Total,
Arch: hi.KernelArch,
Virtualization: hi.VirtualizationSystem,
@ -77,13 +82,18 @@ func GetState(delay int64) *model.HostState {
cpuPercent = cp[0]
}
// Disk
u, _ := disk.Usage("/")
u, _ := disk.Partitions(false)
var used uint64
for _, dev := range u {
usage, _ := disk.Usage(dev.Mountpoint)
used += usage.Used
}
return &model.HostState{
CPU: cpuPercent,
MemUsed: mv.Used,
SwapUsed: ms.Used,
DiskUsed: u.Used,
DiskUsed: used,
NetInTransfer: atomic.LoadUint64(&netInTransfer),
NetOutTransfer: atomic.LoadUint64(&netOutTransfer),
NetInSpeed: atomic.LoadUint64(&netInSpeed),