tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

raidframe status overview script



I got fed up with the lack of any kind of "overview of RAIDframe
status" capability, and if there's a script out there to present a
summary, I didn't find it.  (Which doesn't mean much; I'm not much good
at finding things on the Web.)

So I hacked one together.  Here it is, for anyone who cares.  The idea
is to produce a short summary overview; I found myself with 14 RAIDs on
a machine and very much wanted something like this.  It's just a bit of
awk postprocessing on raidctl -s output, for each raid*.  Works for me
on 4.0.1, and I don't see anything here that isn't bog-standard; maybe
it will be useful to someone.

There are probably some issues relating to the less common states for
members.  The output logic is based partly on observation and partly on
raidctl(1); it may need work if the doc doesn't describe reality
(though I've not caught it out in any such), and it may be possible to
improve where some data appears.  I'd be interested in any such
improvements.

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

#! /bin/sh
# Public domain.
sysctl -n hw.disknames |
  tr \  \\n |
  egrep \^raid |
  sort +0.4n |
  while read r
  do
        echo -n $r":"
        raidctl -s $r |
          awk 'BEGIN {
                        in_disks = 0;
                        in_spares = 0;
                        nd = 0;
                        havelevel[""] = 0;
                        delete havelevel[""];
                }
                /^Components:/ { in_disks = 1; next; }
                /^Spares:/ { in_spares = 1; in_disks = 0; next; }
                /^No spares/ { in_spares = 0; in_disks = 0; next; }
                /^Component label for / {
                        in_disks = 0;
                        in_spares = 0;
                        curdisk = substr($4,2,length($4)-1);
                        next;
                }
                /^   RAID Level:/ {
                        raidlevel[curdisk] = $3;
                        havelevel[$3] = 1;
                        next;
                }
                /^Parity status:/ { parstat = $3; next; }
                /^Reconstruction is/ { recon = $3; next; }
                /^Parity Re-write/ { rewrite = $4; next; }
                /^Copyback is/ { cback = $3; next; }
                in_disks || in_spares {
                        d = substr($1,1,length($1)-1);
                        disks[nd] = d;
                        $1 = "";
                        diskstate[d] = substr($0,2,length($0)-1);
                        havestate[diskstate[d]] = 1;
                        nd ++;
                }
                END {
                        nlev = 0;
                        for (x in havelevel) { nlev ++; lev = x; }
                        if (nlev == 1) { printf(" L%s",lev); }
                        for (i=0;i<nd;i++) {
                                d = disks[i];
                                if ((d ~ /^component[0-9]*$/) && (diskstate[d] 
== "failed")) { continue; }
                                printf(" %s",d);
                                if (nlev != 1) printf("(L%s)",raidlevel[d]);
                                if (diskstate[d] == "optimal") {
                                } else if (diskstate[d] == "reconstructing") {
                                        if ("used_spare" in havestate) {
                                                printf("[failed-spared]");
                                        } else {
                                                printf("[recon:%s]",recon);
                                        }
                                } else if (diskstate[d] == "used_spare") {
                                        if ("reconstructing" in havestate) {
                                                printf("[spare:%s]",recon);
                                        } else {
                                                printf("[%s]",diskstate[d]);
                                        }
                                } else {
                                        printf("[%s]",diskstate[d]);
                                }
                        }
                        if ((recon != "100%") && !("reconstructing" in 
havestate)) {
                                printf(" (recon %s)",recon);
                        }
                        if (rewrite != "100%") {
                                printf(" (rewrite %s)",rewrite);
                        }
                        if (cback != "100%") {
                                printf(" (copyback %s)",cback);
                        }
                        printf("\n");
                }'
  done


Home | Main Index | Thread Index | Old Index