Mdstat - file /proc/mdstat
- class insights.parsers.mdstat.Mdstat(context, extra_bad_lines=None)[source]
Bases:
CommandParser
Represents the information in the
/proc/mdstat
file. Several examples of possible data containe in the file can be found on the MDstat kernel.org wiki page.In particular, the discussion here will focus on initial extraction of information form lines such as:
Personalities : [raid1] [raid6] [raid5] [raid4] md1 : active raid1 sdb2[1] sda2[0] 136448 blocks [2/2] [UU] md2 : active raid1 sdb3[1] sda3[0] 129596288 blocks [2/2] [UU] md3 : active raid5 sdl1[9] sdk1[8] sdj1[7] sdi1[6] sdh1[5] sdg1[4] sdf1[3] sde1[2] sdd1[1] sdc1[0] 1318680576 blocks level 5, 1024k chunk, algorithm 2 [10/10] [UUUUUUUUUU] unused devices: <none>
The data contained in
mdstat
is represented with three top level members -personalities
,components
andmds
.- personalities
A list of RAID levels the kernel currently supports.
- Type:
list
- components
A list containing a dict of md component device information. Each of these dicts contains the following keys
device_name
: string - name of the array deviceactive
: boolean -True
if the array is active,False
if it is inactive.component_name
: string - name of the component deviceraid
: string - with the raid level, e.g., “raid1” for “md1”role
: int - raid role numberdevice_flag
: str - device component status flag. Known values include ‘F’ (failed device), ‘S’, and ‘W’up
: boolean -True
if the component device is upauto_read_only
: boolean -True
if the array device is “auto-read-only”blocks
: the number of blocks in the devicelevel
: the current RAID level, if found in the status linechunk
: the device chunk size, if found in the status linealgorithm
: the current conflict resolution algorithm, if found in the status line
- Type:
list
- mds
A dictionary keyed on the MD device name. Each dict contains the following keys
name
: Name of the MD deviceactive
: Whether the MD device is activeraid
: The RAID type stringdevices
: a list of the devices in thisblocks
,level
,chunk
andalgorithm
- the same information given above per component device (if found)
- Type:
dict
Examples
>>> type(mdstat) <class 'insights.parsers.mdstat.Mdstat'> >>> mdstat.personalities ['raid1', 'raid6', 'raid5', 'raid4'] >>> len(mdstat.components) 14 >>> mdstat.components[0]['device_name'] 'md1' >>> sdb2 = mdstat.components[0] >>> sdb2['component_name'] 'sdb2' >>> sdb2['active'] True >>> sdb2['raid'] 'raid1' >>> sdb2['role'] 1 >>> sdb2['up'] True >>> sorted(mdstat.mds.keys()) ['md1', 'md2', 'md3'] >>> mdstat.mds['md1']['active'] True >>> len(mdstat.mds['md1']['devices']) 2 >>> mdstat.mds['md1']['devices'][0]['component_name'] 'sdb2'
- insights.parsers.mdstat.apply_upstring(upstring, component_list)[source]
Update the dictionaries resulting from
parse_array_start
with the “up” key based on the upstring returned fromparse_upstring
.The function assumes that the upstring and component_list parameters passed in are from the same device array stanza of a
/proc/mdstat
file.The function modifies component_list in place, adding or updating the value of the “up” key to True if there is a corresponding
U
in the upstring string, or to False if there is a corresponding_
.If there the number of rows in component_list does not match the number of characters in upstring, an
AssertionError
is raised.- Parameters:
upstring (str) -- String sequence of
U``s and ``_``s as determined by the ``parse_upstring
method.component_list (list) -- List of dictionaries output from the
parse_array_start
method.
- insights.parsers.mdstat.parse_array_start(md_line)[source]
Parse the initial line of a device array stanza in
/proc/mdstat
.Sample of md_line:
md2 : active raid1 sdb3[1] sda3[0]
- Parameters:
md_line (str) -- A single line from the start of a device array stanza.
- Returns:
- A list of dictionaries, one dictionary for each component
device making up the array.
- Return type:
list
- Raises:
ParseException -- If the format isn’t like the sample above.
- insights.parsers.mdstat.parse_array_status(line, components)[source]
Parse the array status line, e.g.:
1318680576 blocks level 5, 1024k chunk, algorithm 2 [10/10] [UUUUUUUUUU]
This retrieves the following pieces of information:
blocks
- (int) number of blocks in the whole MD device (always present)level
- (int) if found, the present RAID levelchunksize
- (str) if found, the size of the data chunk in kilobytesalgorithm
- (int) if found, the current algorithm in use.
Because of the way data is stored per-component and not per-array, this then puts the above keys into each of the component dictionaries in the list we’ve been given.
Sample data:
1250241792 blocks super 1.2 level 5, 64k chunk, algorithm 2 [5/5] [UUUUUU] 1465151808 blocks level 5, 64k chunk, algorithm 2 [4/3] [UUU_] 136448 blocks [2/2] [UU] 6306 blocks super external:imsm<Paste>
- Parameters:
line (str) -- The array status line to parse.
components (list) -- A list of component dicts.
- insights.parsers.mdstat.parse_personalities(personalities_line)[source]
Parse the “personalities” line of
/proc/mdstat
.Sample of personalities_line:
Personalities : [linear] [raid0] [raid1] [raid5] [raid4] [raid6]
- Parameters:
personalities_line (str) -- A single “Personalities” line from an
files. (/proc/mdstat)
- Returns:
A list of raid “personalities” listed on the line.
- Return type:
list
- Raises:
ParseException -- If the format isn’t like the sample above.
- insights.parsers.mdstat.parse_upstring(line)[source]
Parse the subsequent lines of a device array stanza in
/proc/mdstat
for the “up” indicator string. The up indicator is “U” and down indicator is “_”.Samples of line:
129596288 blocks [2/2] [UU] 1318680576 blocks level 5, 1024k chunk, algorithm 2 [10/10] [UUU_UUUUUU]
- Parameters
line (str): A single line from a device array stanza.
- Returns:
The string containing a series of
U
and_
characters if found in the string, andNone
if the up string is not found.- Return type:
str