mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 21:59:53 +05:00
format status memory sizes
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user