command: quota status reports network usage

This commit is contained in:
Lang Martin 2019-11-20 14:01:10 -05:00 committed by Lang Martin
parent 5e2ee1e237
commit 2e2c662977
2 changed files with 15 additions and 5 deletions

View file

@ -155,7 +155,7 @@ func formatQuotaLimits(spec *api.QuotaSpec, usages map[string]*api.QuotaUsage) s
sort.Sort(api.QuotaLimitSort(spec.Limits))
limits := make([]string, len(spec.Limits)+1)
limits[0] = "Region|CPU Usage|Memory Usage"
limits[0] = "Region|CPU Usage|Memory Usage|Network Usage"
i := 0
for _, specLimit := range spec.Limits {
i++
@ -171,17 +171,27 @@ func formatQuotaLimits(spec *api.QuotaSpec, usages map[string]*api.QuotaUsage) s
return used, ok
}
specBits := 0
if len(specLimit.RegionLimit.Networks) == 1 {
specBits = *specLimit.RegionLimit.Networks[0].MBits
}
used, ok := lookupUsage()
if !ok {
cpu := fmt.Sprintf("- / %s", formatQuotaLimitInt(specLimit.RegionLimit.CPU))
memory := fmt.Sprintf("- / %s", formatQuotaLimitInt(specLimit.RegionLimit.MemoryMB))
limits[i] = fmt.Sprintf("%s|%s|%s", specLimit.Region, cpu, memory)
net := fmt.Sprintf("- / %s", formatQuotaLimitInt(&specBits))
limits[i] = fmt.Sprintf("%s|%s|%s|%s", specLimit.Region, cpu, memory, net)
continue
}
cpu := fmt.Sprintf("%d / %s", *used.RegionLimit.CPU, formatQuotaLimitInt(specLimit.RegionLimit.CPU))
memory := fmt.Sprintf("%d / %s", *used.RegionLimit.MemoryMB, formatQuotaLimitInt(specLimit.RegionLimit.MemoryMB))
limits[i] = fmt.Sprintf("%s|%s|%s", specLimit.Region, cpu, memory)
net := fmt.Sprintf("- / %s", formatQuotaLimitInt(&specBits))
if len(used.RegionLimit.Networks) == 1 {
net = fmt.Sprintf("%d / %s", *used.RegionLimit.Networks[0].MBits, formatQuotaLimitInt(&specBits))
}
limits[i] = fmt.Sprintf("%s|%s|%s|%s", specLimit.Region, cpu, memory, net)
}
return formatList(limits)

View file

@ -36,6 +36,6 @@ Description = Limit the shared default namespace
Limits = 1
Quota Limits
Region CPU Usage Memory Usage
global 500 / 2500 256 / 2000
Region CPU Usage Memory Usage Network Usage
global 500 / 2500 256 / 2000 30 / 50
```