Skip to content

Commit

Permalink
server_info: fix wrong result in memory load (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deardrops authored Apr 9, 2020
1 parent ed3bd6f commit 7480a11
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions load_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ func getMemLoad() []*pb.ServerInfoItem {
var results []*pb.ServerInfoItem
virt, err := mem.VirtualMemory()
if err == nil {
memUsed := virt.Total - virt.Available
memUsedPercent := float64(memUsed) / float64(virt.Total)

results = append(results, &pb.ServerInfoItem{
Tp: "memory",
Name: "virtual",
Pairs: []*pb.ServerInfoPair{
{Key: "total", Value: fmt.Sprintf("%d", virt.Total)},
{Key: "used", Value: fmt.Sprintf("%d", virt.Used)},
{Key: "free", Value: fmt.Sprintf("%d", virt.Free)},
{Key: "used-percent", Value: fmt.Sprintf("%.2f", float64(virt.Used)/float64(virt.Total))},
{Key: "free-percent", Value: fmt.Sprintf("%.2f", float64(virt.Free)/float64(virt.Total))},
{Key: "used", Value: fmt.Sprintf("%d", memUsed)},
{Key: "free", Value: fmt.Sprintf("%d", virt.Available)},
{Key: "used-percent", Value: fmt.Sprintf("%.2f", memUsedPercent)},
{Key: "free-percent", Value: fmt.Sprintf("%.2f", 1-memUsedPercent)},
},
})
}
Expand Down

0 comments on commit 7480a11

Please sign in to comment.