question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add parser for mdadm

See original GitHub issue

Linux software RAID is usually implemented with the md kernel module and managed with the mdadm userspace tool. Unfortunately mdadm doesn’t output it’s data in a format convenient for further automated processing like json.

For example when using mdadm --query --detail /dev/md0 the output looks like this:

/dev/md0:
           Version : 1.1
     Creation Time : Tue Apr 13 23:22:16 2010
        Raid Level : raid1
        Array Size : 5860520828 (5.46 TiB 6.00 TB)
     Used Dev Size : 5860520828 (5.46 TiB 6.00 TB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Tue Jul 26 20:16:31 2022
             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : bitmap

              Name : virttest:0
              UUID : 85c5b164:d58a5ada:14f5fe07:d642e843
            Events : 2193679

    Number   Major   Minor   RaidDevice State
       3       8       17        0      active sync   /dev/sdb1
       2       8       33        1      active sync   /dev/sdc1

mdadm also has the “examine” command which gives information about a md raid member device:

# mdadm --examine -E /dev/sdb1
/dev/sdb1:
          Magic : a92b4efc
        Version : 1.1
    Feature Map : 0x1
     Array UUID : 85c5b164:d58a5ada:14f5fe07:d642e843
           Name : virttest:0
  Creation Time : Tue Apr 13 23:22:16 2010
     Raid Level : raid1
   Raid Devices : 2

 Avail Dev Size : 11721041656 sectors (5.46 TiB 6.00 TB)
     Array Size : 5860520828 KiB (5.46 TiB 6.00 TB)
    Data Offset : 264 sectors
   Super Offset : 0 sectors
   Unused Space : before=80 sectors, after=0 sectors
          State : clean
    Device UUID : 813162e5:2e865efe:02ba5570:7003165c

Internal Bitmap : 8 sectors from superblock
    Update Time : Tue Jul 26 20:16:31 2022
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : f141a577 - correct
         Events : 2193679


   Device Role : Active device 0
   Array State : AA ('A' == active, '.' == missing, 'R' == replacing)

Having a parser for this in jc would be really helpful when dealing with md raid in scripts.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
g-v-egidycommented, Aug 17, 2022

I tested your latest version. It is looking very good to me now, it now gets all values I care for and some more.

Thank you for implementing this parser.

1reaction
g-v-egidycommented, Aug 7, 2022

I don’t have a raid setup so it’s a little difficult for me to check out all of the output possibilities.

Just an idea if you want to try it for yourself: use a virtual machine and add a second, empty virtual disk to it. Then you can use that to play around with the different setups. This is what I have been doing to create the output examples.

I’ve been using https://www.system-rescue.org/ as linux in the virtual machine, because you don’t have to install anything, just add the iso image and it boots.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to parse and process Linux Software RAID events
Create mdmonitor.sh shell script to parse Linux Software RAID events. #!/bin/sh # Parse and process software raid [mdadm] events # Script ...
Read more >
mdadm(8) - Linux manual page - man7.org
Incremental Assembly Add a single device to an appropriate array. If the addition of the device makes the array runnable, the array will...
Read more >
command /usr/sbin/mdadm -E {device} - insights-core
Parser for output of mdadm -E for each MD device in system. This stores the information from the output in the following properties:...
Read more >
Mdadm(Software Raid) & SMART monitoring #840 - GitHub
If we can do some good SMART parsing, we could get rid of hddtemp since it basically reads SMART data.
Read more >
Parsing mdadm output with paste - Major Hayden
My curiosity is always piqued when I find new ways to manipulate command line output in simple ways. While working on a solution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found