Mdstat - file /proc/mdstat
¶
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]
The data contained in mdstat
is represented with three top level members -
personalities
, components
and mds
.
Examples
>>> mdstat = shared[Mdstat]
>>> mdstat.personalities
['raid1', 'raid6', 'raid5', 'raid4']
>>> len(mdstat.components) # The individual component devices
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()) # dictionary of MD devices by device name
['md1', 'md2', 'md3']
>>> mdstat.mds['md1']['active']
True
>>> len(mdstat.mds['md1']['devices']) # list of devices in this MD
2
>>> mdstat.mds['md1']['devices'][0]['component_name'] # device information
'sdb2'
-
class
insights.parsers.mdstat.
Mdstat
(context, extra_bad_lines=[])[source]¶ Bases:
insights.core.CommandParser
Represents the information in the
/proc/mdstat
file.-
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 of dicts
-
mds
¶ A dictionary keyed on the MD device name, with 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 of dicts
-
-
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
methodcomponent_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
.Lines are expected to be like:
md2 : active raid1 sdb3[1] sda3[0]
If they do not have this format, an error will be raised since it would be considered an unexpected parsing error.
- Parameters
md_line (str) -- A single line from the start of a device array stanza from a
/proc/mdstat
file.- Returns
A list of dictionaries, one dictionrary for each component
device making up the array.
-
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>
-
insights.parsers.mdstat.
parse_personalities
(personalities_line)[source]¶ Parse the “personalities” line of
/proc/mdstat
.Lines are expected to be like:
Personalities : [linear] [raid0] [raid1] [raid5] [raid4] [raid6]
If they do not have this format, an error will be raised since it would be considered an unexpected parsing error.
- Parameters
personalities_line (str) -- A single “Personalities” line from an
/proc/mdstat
files.- Returns
- Return type
A list of raid “personalities” listed on the line.
-
insights.parsers.mdstat.
parse_upstring
(line)[source]¶ Parse the subsequent lines of a device array stanza in
/proc/mdstat
for the “up” indictor string.Lines are expected to be like:
129596288 blocks [2/2] [UU]
or
1318680576 blocks level 5, 1024k chunk, algorithm 2 [10/10] [UUU_UUUUUU]
In particular, this method searchs for the string like
[UU]
which indicates whether component devices or up,U
or down,_
.- Parameters
line (str) -- A single line from a device array stanza.
- Returns
The string containing a series of
U
and\_
characters iffound in the string, and
None
if the uptime string is not found.