Adding a RAID monitor to an i3wm status bar.

My home PC has two spinning rust disks that are configured as a RAID 1 disk array. This is great and works well as a media server, a borg backup repository for the various devices around the house.

Every month, a raid-check is automagically run - which I usually forget about and I’ve been known to power off or reboot while it is being perfomed. It typically takes ~ 16 hours.

What I wanted was two indications in an i3blocks status bar that lets me know that:

  • the RAID is healthy (or not)
  • the RAID is being checked and how long it will take to finish

Some notes about the code. I am writing stuff using fish shell because I am merely ok at it, even though I use it every day. I feel I should be much better consideiring the amount of time I spend using it, so I’m forcing myself to use it for scripts in order to improve. I am really good at perl and bash and other stuff, but would not learn so much.

RAID health status

Here is the code that i3blocks parses to display RAID health

#!/usr/bin/fish
if test -e /proc/mdstat

    if set --local s ( cat /proc/mdstat | awk '/^md/ {printf "%s ", $1}; /blocks/ {print $NF}' )

    # 'md0 [UU]' to 'md999 [UUUUUUUUUUUU...]' will pass. 'md0 [U_]' will fail etc

      if string match --regex '^md[0-9]{1,3}\s\[[U]{2,}\]' $s #xkcd 208
            echo
            echo "#00ff00"
        else
            echo "👀 RAID: $s 👀"                
            echo
            echo "#E10600"
        end

    end

end

RAID check status

I only want to see the time to complete a raid check when it is running and have created a fish function for this so I can call it from any shell.

Here is the code:

function raid_time_remaining

    if set --local s ( grep finish /proc/mdstat )

        set --local m   ( echo $s | awk '{print $6}' | sed 's/finish=//' | sed 's/min//' )
        set --local mm  ( math floor $m %60 )
        set --local hh  ( math --scale 0 floor $m / 60 )
        printf "⏳ %dh %02dm" $hh $mm

    end

end

The wrapper for i3blocks is

#!/usr/bin/fish

echo (raid_time_remaining)
echo
echo "#FFA500"

A not very exciting image showing i3blocks status bar:

Portrait desktop sway screenshot