Disk free space commands
Module for the processing of output from the df command. The base class
DiskFree provides all of the functionality for all classes.
Data is avaliable as rows of the output contained in one Record object
for each line of output.
Parsers contained in this module are:
DiskFree_LI - command df -li
DiskFree_ALP - command df -alP
DiskFree_AL - command df -al
- class insights.parsers.df.DiskFree(context)[source]
Bases:
CommandParserClass to provide methods used by all
dfcommand classes.- filesystems
Dictionary with each entry being a list of
Recordobjects, for all lines in the command output. The dictionary is keyed by thefilesystemvalue of the Record.- Type:
dict of list
- mounts
Dictionary with each entry being a
Recordobject corresponding to themounted_onkey.- Type:
dict
- Raises:
ParseException -- When there are lines cannot be parsed or the
block sizecannot be recognized.
- property filesystem_names
Returns list of unique filesystem names.
- Type:
list
- get_dir(path)[source]
Record: returns the Record object that contains the given path.
This finds the most specific mount path that contains the given path.
- property mount_names
Returns list of unique mount point names.
- Type:
list
- class insights.parsers.df.DiskFree_AL(context)[source]
Bases:
DiskFreeParse lines from the output of the
df -alcommand.Typical content of the
df -alcommand looks like:Filesystem 1K-blocks Used Available Use% Mounted on sysfs 0 0 0 - /sys proc 0 0 0 - /proc devtmpfs 968896 0 968896 0% /dev securityfs 0 0 0 - /sys/kernel/security tmpfs 984112 0 984112 0% /dev/shm devpts 0 0 0 - /dev/pts tmpfs 984112 8660 975452 1% /run tmpfs 984112 0 984112 0% /sys/fs/cgroup cgroup 0 0 0 - /sys/fs/cgroup/systemd cgroup 0 0 0 - /sys/fs/cgroup/pids cgroup 0 0 0 - /sys/fs/cgroup/rdma configfs 0 0 0 - /sys/kernel/config /dev/sda2 17813504 2127172 15686332 12% / selinuxfs 0 0 0 - /sys/fs/selinux systemd-1 - - - - /proc/sys/fs/binfmt_misc debugfs 0 0 0 - /sys/kernel/debug mqueue 0 0 0 - /dev/mqueue hugetlbfs 0 0 0 - /dev/hugepages /dev/sdb1 52402180 1088148 51314032 3% /V M T o o l s /dev/sda1 1038336 185676 852660 18% /boot
- data
A list of the
dfinformation with oneRecordobject for each line of command output. Mapping of input columns to output fields is:Input column Output Field ------------ ------------ Filesystem filesystem 1K-blocks total Used used Available available Use% capacity Mounted on mounted_on
- Type:
list
- raw_block_size
The unit of display values.
- Type:
str
- block_size
The unit of display values, which is converted to integer.
- Type:
int
Examples
>>> len(df_al) 20 >>> len(df_al.filesystem_names) 16 >>> df_al.raw_block_size '1K' >>> df_al.block_size 1024 >>> df_al.get_filesystem('/dev/sda2')[0].mounted_on == '/' True >>> '/V M T o o l s' in df_al.mount_names True >>> df_al.get_mount('/').used '2127172' >>> int(int(df_al.get_mount('/').used) * df_alP.block_size / 1024) # to KB 2127172 >>> int(int(df_al.get_mount('/').used) * df_alP.block_size / 1024 / 1024) # to MB 2077 >>> [d.mounted_on for d in df_al if 'sda' in d.filesystem] == ['/', '/boot'] True >>> df_al.data[0].filesystem == 'sysfs' True
- class insights.parsers.df.DiskFree_ALP(context)[source]
Bases:
DiskFreeParse lines from the output of the
df -alPcommand.Typical content of the
df -alPcommand looks like:Filesystem 1024-blocks Used Available Capacity Mounted on sysfs 0 0 0 - /sys proc 0 0 0 - /proc devtmpfs 968896 0 968896 0% /dev securityfs 0 0 0 - /sys/kernel/security tmpfs 984112 0 984112 0% /dev/shm devpts 0 0 0 - /dev/pts tmpfs 984112 8660 975452 1% /run tmpfs 984112 0 984112 0% /sys/fs/cgroup cgroup 0 0 0 - /sys/fs/cgroup/systemd cgroup 0 0 0 - /sys/fs/cgroup/pids cgroup 0 0 0 - /sys/fs/cgroup/rdma configfs 0 0 0 - /sys/kernel/config /dev/sda2 17813504 2127172 15686332 12% / selinuxfs 0 0 0 - /sys/fs/selinux systemd-1 - - - - /proc/sys/fs/binfmt_misc debugfs 0 0 0 - /sys/kernel/debug mqueue 0 0 0 - /dev/mqueue hugetlbfs 0 0 0 - /dev/hugepages /dev/sdb1 52402180 1088148 51314032 3% /V M T o o l s /dev/sda1 1038336 185676 852660 18% /boot
- data
A list of the
dfinformation with oneRecordobject for each line of command output. Mapping of input columns to output fields is:Input column Output Field ------------ ------------ Filesystem filesystem 1024-blocks total Used used Available available Capacity capacity Mounted on mounted_on
- Type:
list
- raw_block_size
The unit of display values.
- Type:
str
- block_size
The unit of display values, which is converted to integer.
- Type:
int
Examples
>>> len(df_alP) 20 >>> len(df_alP.filesystem_names) 16 >>> df_alP.raw_block_size '1024' >>> df_alP.block_size 1024 >>> df_alP.get_filesystem('/dev/sda2')[0].mounted_on == '/' True >>> '/V M T o o l s' in df_alP.mount_names True >>> df_alP.get_mount('/boot').available '852660' >>> int(int(df_alP.get_mount('/boot').available) * df_alP.block_size / 1024) # to KB 852660 >>> int(int(df_alP.get_mount('/boot').available) * df_alP.block_size / 1024 / 1024) # to MB 832 >>> [d.mounted_on for d in df_alP if 'sda' in d.filesystem] == ['/', '/boot'] True >>> df_alP.data[0].filesystem == 'sysfs' True
- class insights.parsers.df.DiskFree_LI(context)[source]
Bases:
DiskFreeParse lines from the output of the
df -licommand.Typical content of the
df -licommand output looks like:Filesystem Inodes IUsed IFree IUse% Mounted on devtmpfs 242224 359 241865 1% /dev tmpfs 246028 1 246027 1% /dev/shm tmpfs 246028 491 245537 1% /run tmpfs 246028 17 246011 1% /sys/fs/cgroup /dev/sda2 8911872 58130 8853742 1% / /dev/sdb1 26213888 19662 26194226 1% /opt/data /dev/sda1 524288 306 523982 1% /boot tmpfs 246028 5 246023 1% /run/user/0
- data
A list of the
dfinformation with oneRecordobject for each line of command output. Mapping of input columns to output fields is:Input column Output Field ------------ ------------ Filesystem filesystem Inodes total IUsed used IFree available IUse% capacity Mounted on mounted_on
- Type:
list
Examples
>>> len(df_li) 8 >>> len(df_li.filesystem_names) 5 >>> df_li.get_filesystem('/dev/sda1')[0].mounted_on == '/boot' True >>> '/opt/data' in df_li.mount_names True >>> df_li.get_mount('/sys/fs/cgroup').available == '246011' True >>> [d.mounted_on for d in df_li if 'sda' in d.filesystem] == ['/', '/boot'] True >>> df_li.data[0].filesystem == 'devtmpfs' True >>> df_li.data[0].capacity == '1%' True
- class insights.parsers.df.Record(filesystem, total, used, available, capacity, mounted_on)
Bases:
tuplenamedtuple: Represents the information parsed from
dfcommand output.- available
- capacity
- filesystem
- mounted_on
- total
- used
- insights.parsers.df.parse_df_lines(df_content)[source]
Parse contents of each line in
dfoutput.Parse each line of
dfoutput ensuring that wrapped lines are reassembled prior to parsing, and that mount names containing spaces are maintained.- Parameters:
df_content (list) -- Lines of df output to be parsed.
- Returns:
A list of
Recordnamedtuple’s. One for each line of thedfoutput with columns as the key values. The fields ofRecordprovide information about the file system attributes as determined by the arguments to thedfcommand. So, for example, ifdfis given the-alP, the values are in terms of 1024 blocks. If-liis given, then the values are in terms of inodes:- filesystem: Name of the filesystem - total (str): total number of resources on the filesystem - used (str): number of the resources used on the filesystem - available (str): number of the resource available on the filesystem - capacity (str): percentage of the resource used on the filesystem - mounted_on: mount point of the filesystem
- Return type:
list