Disk Usage parsers

Module for the processing of output from the du command.

Parsers provided by this module include:

DiskUsageDir - command du -s -k {directory}

class insights.parsers.du.DiskUsage(context, extra_bad_lines=None)[source]

Bases: CommandParser, dict

Reads output of du command and turns it into a dictionary with pathname as key and size in blocks.

Supports parsing input data as long as output is 2 column data with first column as space size with integer values only and second as pathname which can be a file or directory. Space size with decimal values or unit suffixes like M, GiB is not supported.

du command produces output in 1K blocks unless block size is specified in command options or an environment variable. This parser is intended to be used only with default block size of 1K which is also equal to plain “du” or “du -k”.

Sample input data:

56      /var/lib/alternatives
4       /var/lib/logrotate
5492    /var/lib/mlocate
20      /var/lib/NetworkManager
186484  /var/lib/pgsql
856     /var/lib/rhsm
110712  /var/lib/rpm
4       /var/lib/rsyslog
64      /var/lib/systemd
15200   /var/lib/yum


>>> '/var/lib/pgsql' in disk_usage
>>> disk_usage.get('/var/lib/pgsql')
>>> int(disk_usage.get('/var/lib/pgsql') / 1024) # to MiB

Parse input data into a dictionary.

class insights.parsers.du.DiskUsageDir(context, extra_bad_lines=None)[source]

Bases: DiskUsage

Parser class for processing du output for multiple directories, each collected using du -s -k {directory}.