Add 'MemUsageBytes' format option
Although storage is more human-readable when expressed in SI units, IEC/JEDEC (Bytes) units are more pertinent for memory-related values (and match the format of the --memory* command-line options). (To prevent possible compatibility issues, the default SI display is left unchanged) See https://github.com/containers/podman/issues/8945 Signed-off-by: Stuart Shelton <stuart@shelton.me>
This commit is contained in:
parent
265ec914d3
commit
a6af56f5b4
|
@ -150,6 +150,7 @@ func outputStats(reports []define.ContainerStats) error {
|
||||||
"ID": "ID",
|
"ID": "ID",
|
||||||
"CPUPerc": "CPU %",
|
"CPUPerc": "CPU %",
|
||||||
"MemUsage": "MEM USAGE / LIMIT",
|
"MemUsage": "MEM USAGE / LIMIT",
|
||||||
|
"MemUsageBytes": "MEM USAGE / LIMIT",
|
||||||
"MemPerc": "MEM %",
|
"MemPerc": "MEM %",
|
||||||
"NetIO": "NET IO",
|
"NetIO": "NET IO",
|
||||||
"BlockIO": "BLOCK IO",
|
"BlockIO": "BLOCK IO",
|
||||||
|
@ -222,10 +223,15 @@ func (s *containerStats) PIDS() string {
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%d", s.PIDs)
|
return fmt.Sprintf("%d", s.PIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *containerStats) MemUsage() string {
|
func (s *containerStats) MemUsage() string {
|
||||||
return combineHumanValues(s.ContainerStats.MemUsage, s.ContainerStats.MemLimit)
|
return combineHumanValues(s.ContainerStats.MemUsage, s.ContainerStats.MemLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *containerStats) MemUsageBytes() string {
|
||||||
|
return combineBytesValues(s.ContainerStats.MemUsage, s.ContainerStats.MemLimit)
|
||||||
|
}
|
||||||
|
|
||||||
func floatToPercentString(f float64) string {
|
func floatToPercentString(f float64) string {
|
||||||
strippedFloat, err := utils.RemoveScientificNotationFromFloat(f)
|
strippedFloat, err := utils.RemoveScientificNotationFromFloat(f)
|
||||||
if err != nil || strippedFloat == 0 {
|
if err != nil || strippedFloat == 0 {
|
||||||
|
@ -242,6 +248,13 @@ func combineHumanValues(a, b uint64) string {
|
||||||
return fmt.Sprintf("%s / %s", units.HumanSize(float64(a)), units.HumanSize(float64(b)))
|
return fmt.Sprintf("%s / %s", units.HumanSize(float64(a)), units.HumanSize(float64(b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func combineBytesValues(a, b uint64) string {
|
||||||
|
if a == 0 && b == 0 {
|
||||||
|
return "-- / --"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s / %s", units.BytesSize(float64(a)), units.BytesSize(float64(b)))
|
||||||
|
}
|
||||||
|
|
||||||
func outputJSON(stats []containerStats) error {
|
func outputJSON(stats []containerStats) error {
|
||||||
type jstat struct {
|
type jstat struct {
|
||||||
Id string `json:"id"` // nolint
|
Id string `json:"id"` // nolint
|
||||||
|
|
|
@ -77,6 +77,7 @@ func stats(cmd *cobra.Command, args []string) error {
|
||||||
headers := report.Headers(entities.PodStatsReport{}, map[string]string{
|
headers := report.Headers(entities.PodStatsReport{}, map[string]string{
|
||||||
"CPU": "CPU %",
|
"CPU": "CPU %",
|
||||||
"MemUsage": "MEM USAGE/ LIMIT",
|
"MemUsage": "MEM USAGE/ LIMIT",
|
||||||
|
"MemUsageBytes": "MEM USAGE/ LIMIT",
|
||||||
"MEM": "MEM %",
|
"MEM": "MEM %",
|
||||||
"NET IO": "NET IO",
|
"NET IO": "NET IO",
|
||||||
"BlockIO": "BLOCK IO",
|
"BlockIO": "BLOCK IO",
|
||||||
|
|
|
@ -36,12 +36,13 @@ Pretty-print container statistics to JSON or using a Go template
|
||||||
Valid placeholders for the Go template are listed below:
|
Valid placeholders for the Go template are listed below:
|
||||||
|
|
||||||
| **Placeholder** | **Description** |
|
| **Placeholder** | **Description** |
|
||||||
| --------------- | --------------- |
|
| --------------- | ------------------ |
|
||||||
| .Pod | Pod ID |
|
| .Pod | Pod ID |
|
||||||
| .CID | Container ID |
|
| .CID | Container ID |
|
||||||
| .Name | Container Name |
|
| .Name | Container Name |
|
||||||
| .CPU | CPU percentage |
|
| .CPU | CPU percentage |
|
||||||
| .MemUsage | Memory usage |
|
| .MemUsage | Memory usage |
|
||||||
|
| .MemUsageBytes | Memory usage (IEC) |
|
||||||
| .Mem | Memory percentage |
|
| .Mem | Memory percentage |
|
||||||
| .NetIO | Network IO |
|
| .NetIO | Network IO |
|
||||||
| .BlockIO | Block IO |
|
| .BlockIO | Block IO |
|
||||||
|
|
|
@ -46,11 +46,12 @@ Pretty-print container statistics to JSON or using a Go template
|
||||||
Valid placeholders for the Go template are listed below:
|
Valid placeholders for the Go template are listed below:
|
||||||
|
|
||||||
| **Placeholder** | **Description** |
|
| **Placeholder** | **Description** |
|
||||||
| --------------- | --------------- |
|
| --------------- | ------------------ |
|
||||||
| .ID | Container ID |
|
| .ID | Container ID |
|
||||||
| .Name | Container Name |
|
| .Name | Container Name |
|
||||||
| .CPUPerc | CPU percentage |
|
| .CPUPerc | CPU percentage |
|
||||||
| .MemUsage | Memory usage |
|
| .MemUsage | Memory usage |
|
||||||
|
| .MemUsageBytes | Memory usage (IEC) |
|
||||||
| .MemPerc | Memory percentage |
|
| .MemPerc | Memory percentage |
|
||||||
| .NetIO | Network IO |
|
| .NetIO | Network IO |
|
||||||
| .BlockIO | Block IO |
|
| .BlockIO | Block IO |
|
||||||
|
|
|
@ -214,6 +214,7 @@ type PodStatsOptions struct {
|
||||||
type PodStatsReport struct {
|
type PodStatsReport struct {
|
||||||
CPU string
|
CPU string
|
||||||
MemUsage string
|
MemUsage string
|
||||||
|
MemUsageBytes string
|
||||||
Mem string
|
Mem string
|
||||||
NetIO string
|
NetIO string
|
||||||
BlockIO string
|
BlockIO string
|
||||||
|
|
|
@ -46,6 +46,7 @@ func (ic *ContainerEngine) podsToStatsReport(pods []*libpod.Pod) ([]*entities.Po
|
||||||
r := entities.PodStatsReport{
|
r := entities.PodStatsReport{
|
||||||
CPU: floatToPercentString(podStats[j].CPU),
|
CPU: floatToPercentString(podStats[j].CPU),
|
||||||
MemUsage: combineHumanValues(podStats[j].MemUsage, podStats[j].MemLimit),
|
MemUsage: combineHumanValues(podStats[j].MemUsage, podStats[j].MemLimit),
|
||||||
|
MemUsageBytes: combineBytesValues(podStats[j].MemUsage, podStats[j].MemLimit),
|
||||||
Mem: floatToPercentString(podStats[j].MemPerc),
|
Mem: floatToPercentString(podStats[j].MemPerc),
|
||||||
NetIO: combineHumanValues(podStats[j].NetInput, podStats[j].NetOutput),
|
NetIO: combineHumanValues(podStats[j].NetInput, podStats[j].NetOutput),
|
||||||
BlockIO: combineHumanValues(podStats[j].BlockInput, podStats[j].BlockOutput),
|
BlockIO: combineHumanValues(podStats[j].BlockInput, podStats[j].BlockOutput),
|
||||||
|
@ -68,6 +69,13 @@ func combineHumanValues(a, b uint64) string {
|
||||||
return fmt.Sprintf("%s / %s", units.HumanSize(float64(a)), units.HumanSize(float64(b)))
|
return fmt.Sprintf("%s / %s", units.HumanSize(float64(a)), units.HumanSize(float64(b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func combineBytesValues(a, b uint64) string {
|
||||||
|
if a == 0 && b == 0 {
|
||||||
|
return "-- / --"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s / %s", units.BytesSize(float64(a)), units.BytesSize(float64(b)))
|
||||||
|
}
|
||||||
|
|
||||||
func floatToPercentString(f float64) string {
|
func floatToPercentString(f float64) string {
|
||||||
strippedFloat, err := utils.RemoveScientificNotationFromFloat(f)
|
strippedFloat, err := utils.RemoveScientificNotationFromFloat(f)
|
||||||
if err != nil || strippedFloat == 0 {
|
if err != nil || strippedFloat == 0 {
|
||||||
|
|
Loading…
Reference in New Issue