4

I'm running some Docker containers for my users. Users are able to start and stop their containers dynamically, so I would like to watch my Data space available metrics from docker info with some sort of monitoring system.

I've tried to use Docker API directory with

echo -e 'GET /info HTTP/1.0\r\n' |  nc -U /var/run/docker.sock | grep '{'  | python -m json.tool

but the result is returned in human readable units - ie. "16.93 MB" and "9 GB", which is not suitable for machine processing.

The same happens when using Python Docker API library.

import docker
client = docker.Client()
print(client.info()['DriverStatus'])

So the question is: Is there a machine-readable version of docker info for for parsing out "Base Data Space Total" metrics?

030
  • 5,731
  • 12
  • 61
  • 107
Věroš K.
  • 500
  • 3
  • 9

1 Answers1

2

One could use docker info --format '{{json .}}'.

For example:

user@host$ docker info --format '{{json .MemTotal}}'
3840544768
030
  • 5,731
  • 12
  • 61
  • 107
  • Thank you for the answer. It doesn't work on my testing machine, because `--format` flag is not defined in Docker engine 1.12 (on CentOS 7). It seems to be working from Docker 1.13. – Věroš K. Apr 23 '17 at 14:18