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: insights.core.CommandParser

Class to provide methods used by all df command classes.

data

List of Record objects for each line of command output.

Type

list of Record

filesystems

Dictionary with each entry being a list of Record objects, for all lines in the command output. The dictionary is keyed by the filesystem value of the Record.

Type

dict of list

mounts

Dictionary with each entry being a Record object corresponding to the mounted_on key.

Type

dict

Raises

ParseException -- When there are lines cannot be parsed or the block size cannot 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.

get_filesystem(name)[source]

str: Returns list of Record objects for filesystem name.

get_mount(name)[source]

Record: Returns Record obj for mount point name.

property mount_names

Returns list of unique mount point names.

Type

list

parse_content(content)[source]

This method must be implemented by classes based on this class.

class insights.parsers.df.DiskFree_AL(context)[source]

Bases: insights.parsers.df.DiskFree

Parse lines from the output of the df -al command.

Typical content of the df -al command 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 df information with one Record object 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: insights.parsers.df.DiskFree

Parse lines from the output of the df -alP command.

Typical content of the df -alP command 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 df information with one Record object 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: insights.parsers.df.DiskFree

Parse lines from the output of the df -li command.

Typical content of the df -li command 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 df information with one Record object 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: tuple

namedtuple: Represents the information parsed from df command output.

property available
property capacity
property filesystem
property mounted_on
property total
property used
insights.parsers.df.parse_df_lines(df_content)[source]

Parse contents of each line in df output.

Parse each line of df output 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 Record namedtuple’s. One for each line of the df output with columns as the key values. The fields of Record provide information about the file system attributes as determined by the arguments to the df command. So, for example, if df is given the -alP, the values are in terms of 1024 blocks. If -li is 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