From b1bd788c55b7d3d773b920560a2e2576096dc7f1 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Sat, 11 Jun 2016 21:01:53 -0700 Subject: [PATCH] unify units --- command/node_status.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/command/node_status.go b/command/node_status.go index 922483261bd..203fe20c67e 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -16,6 +16,9 @@ import ( const ( // floatFormat is a format string for formatting floats. floatFormat = "#,###.##" + + // bytesPerMegabyte is the number of bytes per MB + bytesPerMegabyte = 1024 * 1024 ) type NodeStatusCommand struct { @@ -402,14 +405,14 @@ func getAllocatedResources(client *api.Client, runningAllocs []*api.Allocation, } resources := make([]string, 2) - resources[0] = "CPU|Memory MB|Disk MB|IOPS" + resources[0] = "CPU|Memory|Disk|IOPS" resources[1] = fmt.Sprintf("%v/%v|%v/%v|%v/%v|%v/%v", cpu, total.CPU, - mem, - total.MemoryMB, - disk, - total.DiskMB, + humanize.Bytes(uint64(mem*bytesPerMegabyte)), + humanize.Bytes(uint64(total.MemoryMB*bytesPerMegabyte)), + humanize.Bytes(uint64(disk*bytesPerMegabyte)), + humanize.Bytes(uint64(total.DiskMB*bytesPerMegabyte)), iops, total.IOPS) @@ -452,14 +455,13 @@ func getActualResources(client *api.Client, runningAllocs []*api.Allocation, nod mem += stats.ResourceUsage.MemoryStats.RSS } - // TODO do humanized output for these resources := make([]string, 2) resources[0] = "CPU|Memory" resources[1] = fmt.Sprintf("%v/%v|%v/%v", math.Floor(cpu), total.CPU, humanize.Bytes(mem), - humanize.Bytes(uint64(total.MemoryMB*1024*1024))) + humanize.Bytes(uint64(total.MemoryMB*bytesPerMegabyte))) return resources, nil }