diff --git a/engine/responder.go b/engine/responder.go index 2e1ff74e9..f0499c1f5 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -592,8 +592,8 @@ func (rs *Responder) Status(arg string, reply *map[string]interface{}) (err erro if rs.Bal != nil { response["Raters"] = rs.Bal.GetClientAddresses() } - response["memstat"] = memstats.HeapAlloc / 1024 - response["footprint"] = memstats.Sys / 1024 + response["memstat"] = utils.SizeFmt(float64(memstats.HeapAlloc), "") + response["footprint"] = utils.SizeFmt(float64(memstats.Sys), "") *reply = response return } diff --git a/utils/coreutils.go b/utils/coreutils.go index 40697a0ea..35453b5d5 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -533,3 +533,17 @@ func GetEndOfMonth(ref time.Time) time.Time { eom := time.Date(year, month, 1, 0, 0, 0, 0, ref.Location()) return eom.Add(-time.Second) } + +// formats number in K,M,G, etc. +func SizeFmt(num float64, suffix string) string { + if suffix == "" { + suffix = "B" + } + for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} { + if math.Abs(num) < 1024.0 { + return fmt.Sprintf("%3.1f%s%s", num, unit, suffix) + } + num /= 1024.0 + } + return fmt.Sprintf("%.1f%s%s", num, "Yi", suffix) +}