snippetdockerMinor
How can I monitor docker volume usage?
Viewed 0 times
canhowdockerusagemonitorvolume
Problem
I'm planning to automate docker activities using python. However, I couldn't find any efficient command for monitoring docker volume. So now I wish to use shell commands for that and later it can be converted using subprocess in python.
My requirement is when I give a volume name then I need the used space, free space, and total space of that volume for finding the storage threshold of the same.
I tried using the
For example, I give the volume name as my_volume then I need storage details of the same only. Hope everyone understood my requirement and excepting a helping hand from someone.
My requirement is when I give a volume name then I need the used space, free space, and total space of that volume for finding the storage threshold of the same.
I tried using the
docker system df -v But it showing all details.For example, I give the volume name as my_volume then I need storage details of the same only. Hope everyone understood my requirement and excepting a helping hand from someone.
Solution
I'd recommend a temporary container for this. It will work on just about any version of docker, and supports named volumes with non-default settings, e.g. that store data on remote systems (e.g. NFS) or modify the bind mound settings to use another folder.
A simple example is:
You can parse that output or reformat with the
A simple example is:
$ docker container run --rm -v "${volume_name}:/volume" -w /volume busybox df -P .
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/.......... 898086280 350169736 502226484 41% /volumeYou can parse that output or reformat with the
df command as appropriate for your use case. The busybox version of df will have fewer options than you may be used to:$ df --help
BusyBox v1.31.1 (2019-12-23 19:20:27 UTC) multi-call binary.
Usage: df [-PkmhTai] [-B SIZE] [FILESYSTEM]...
Print filesystem usage statistics
-P POSIX output format
-k 1024-byte blocks (default)
-m 1M-byte blocks
-h Human readable (e.g. 1K 243M 2G)
-T Print filesystem type
-a Show all filesystems
-i Inodes
-B SIZE BlocksizeCode Snippets
$ docker container run --rm -v "${volume_name}:/volume" -w /volume busybox df -P .
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/.......... 898086280 350169736 502226484 41% /volume$ df --help
BusyBox v1.31.1 (2019-12-23 19:20:27 UTC) multi-call binary.
Usage: df [-PkmhTai] [-B SIZE] [FILESYSTEM]...
Print filesystem usage statistics
-P POSIX output format
-k 1024-byte blocks (default)
-m 1M-byte blocks
-h Human readable (e.g. 1K 243M 2G)
-T Print filesystem type
-a Show all filesystems
-i Inodes
-B SIZE BlocksizeContext
StackExchange DevOps Q#11283, answer score: 2
Revisions (0)
No revisions yet.