Docker Stats Memory and NetIO Format

Hello,

Is is possible to force the output of the docker stats to only show MB or GB. I would like to pull the data from the docker stats output and store it as measures in an APM tool, but one requirement is that the value must be in GB or MB consistently. The issue we are seeing is that some of the boxes are reporting in MB, so the value is inaccurate and reports in the APM tool as 900GB instead of 900MB.

Can someone please help in this?

Unfortunately there is no way to force the docker container stats command to do what you are asking. Your script/code will have to do the conversion itself before storing it.

$ docker container stats --no-trunc --no-stream apache --format '{{ json . }}' | jq
{
  "BlockIO": "0B / 0B",
  "CPUPerc": "0.00%",
  "Container": "apache",
  "ID": "fb893ca3cc0399f730740588b62a96ccf71e1339ab6759ff0b681e59dd78478b",
  "MemPerc": "0.14%",
  "MemUsage": "5.504MiB / 3.855GiB",
  "Name": "apache",
  "NetIO": "1.53kB / 0B",
  "PIDs": "82"
}