root / plugins / disk / raid @ 17f78427
Historique | Voir | Annoter | Télécharger (4,47 ko)
| 1 | 6e292519 | Nathan Rutman | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | 17f78427 | Lars Kruse | # |
| 3 | 6e292519 | Nathan Rutman | # (c) 2007 Nathan Rutman nathan@clusterfs.com |
| 4 | 17f78427 | Lars Kruse | # |
| 5 | # Plugin to monitor RAID status |
||
| 6 | 6e292519 | Nathan Rutman | # |
| 7 | # Results are % of healthy drives in a raid device |
||
| 8 | 17f78427 | Lars Kruse | # and % rebuilt of devices that are resyncing. |
| 9 | 6e292519 | Nathan Rutman | # |
| 10 | #%# family=contrib |
||
| 11 | #%# capabilities=autoconf |
||
| 12 | |||
| 13 | 0f972e1f | Nagy Elemer Karoly | if ($ARGV[0] and $ARGV[0] eq "autoconf") {
|
| 14 | if (-r "/proc/mdstat" and `grep md /proc/mdstat`) {
|
||
| 15 | 2e0acaca | Ken-ichi Mito | print "yes\n"; |
| 16 | exit 0; |
||
| 17 | 0f972e1f | Nagy Elemer Karoly | } else {
|
| 18 | 2e0acaca | Ken-ichi Mito | print "no RAID devices\n"; |
| 19 | exit 1; |
||
| 20 | 6e292519 | Nathan Rutman | } |
| 21 | } |
||
| 22 | |||
| 23 | 0f972e1f | Nagy Elemer Karoly | if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
| 24 | 6e292519 | Nathan Rutman | print "graph_title RAID status\n"; |
| 25 | print "graph_category disk\n"; |
||
| 26 | print "graph_info This graph monitors RAID disk health. Values are percentage of healthy drives in each raid group. Degraded devices are marked Critical.\n"; |
||
| 27 | print "graph_args --base 1000 -l 0\n"; |
||
| 28 | 27d5ca53 | Aaron Parecki | print "graph_vlabel % healthy/rebuilt\n"; |
| 29 | 6e292519 | Nathan Rutman | print "graph_scale no\n"; |
| 30 | } |
||
| 31 | |||
| 32 | 2e0acaca | Ken-ichi Mito | open(my $mdstat, "/proc/mdstat"); |
| 33 | 2670e4dc | Ken-ichi Mito | my(@text) = <$mdstat>; |
| 34 | # contents of <$mdstat> may be changed at next reading, so fetch the contents at a time |
||
| 35 | 2e0acaca | Ken-ichi Mito | close($mdstat); |
| 36 | 6e292519 | Nathan Rutman | |
| 37 | 2670e4dc | Ken-ichi Mito | my($devinfo_re, $devstat_re, $action_re) = ( |
| 38 | 9845279a | Ken-ichi Mito | '(md\d+)\s+:\s+active\s+(\(read-only\)\s+|\(auto-read-only\)\s+|)(\w+)\s+(.*)', |
| 39 | 2670e4dc | Ken-ichi Mito | '.*\[(\d+)\/(\d+)]\s+\[(\w+)]', |
| 40 | 6284302a | Ken-ichi Mito | '.*(reshape|check|resync|recovery)\s*=\s*(\d+\.\d+%|\w+)(.*finish=(.*min))?', |
| 41 | 2670e4dc | Ken-ichi Mito | ); |
| 42 | 9845279a | Ken-ichi Mito | # Interestingly, swap is presented as "active (auto-read-only)" |
| 43 | # and mdadm has '--readonly' option to make the array 'active (read-only)' |
||
| 44 | 2670e4dc | Ken-ichi Mito | |
| 45 | bbec1ffb | Dobrica Pavlinusic | my($dev, $ro, $type, $members, $failed, $nmem, $nact, $status, $action, $proc, $minute); |
| 46 | 2670e4dc | Ken-ichi Mito | while (@text) {
|
| 47 | my $line = shift @text; |
||
| 48 | if ($line =~ /$devinfo_re/) {
|
||
| 49 | # first line should like "active raid1 sda1[0] sdc1[2] sdb1[1]" |
||
| 50 | 760b14f5 | Ken-ichi Mito | $dev = $1; |
| 51 | 6284302a | Ken-ichi Mito | $ro = $2 || ''; |
| 52 | 2670e4dc | Ken-ichi Mito | $type = $3; |
| 53 | $members = $4; |
||
| 54 | bbec1ffb | Dobrica Pavlinusic | $failed = $members; |
| 55 | $failed =~ s/[^F]+//g; |
||
| 56 | $failed = length($failed); |
||
| 57 | 17f78427 | Lars Kruse | |
| 58 | 2670e4dc | Ken-ichi Mito | $line = shift @text; |
| 59 | if ($line =~ /$devstat_re/) {
|
||
| 60 | # second line should like "123456 blocks super 1.2 [2/2] [UU]" |
||
| 61 | $nmem = $1; |
||
| 62 | $nact = $2; |
||
| 63 | $status = $3; |
||
| 64 | } |
||
| 65 | else {
|
||
| 66 | b805f7a6 | Dr. Nagy Elemér Károly | # second line did not exist on /proc/mdstat |
| 67 | 2670e4dc | Ken-ichi Mito | next; |
| 68 | } |
||
| 69 | 17f78427 | Lars Kruse | |
| 70 | 2670e4dc | Ken-ichi Mito | $line = shift @text; |
| 71 | if ($line =~ /$action_re/) {
|
||
| 72 | # third line should like " [==>..................] check = 10.0% (12345/123456) finish=123min speed=12345/sec" |
||
| 73 | # this line will appear only when the array is in action |
||
| 74 | 760b14f5 | Ken-ichi Mito | $action = $1; |
| 75 | my $percent = $2; |
||
| 76 | 6284302a | Ken-ichi Mito | $minute = $4 || ''; |
| 77 | 760b14f5 | Ken-ichi Mito | if ($percent =~ /(\d+\.\d+)%/) {
|
| 78 | $proc = $1; |
||
| 79 | } |
||
| 80 | else {
|
||
| 81 | # 'resync=DELAYED' or 'resync=PENDING' |
||
| 82 | 6284302a | Ken-ichi Mito | $action .= " ($percent)"; |
| 83 | 760b14f5 | Ken-ichi Mito | $proc = -1; |
| 84 | } |
||
| 85 | 2670e4dc | Ken-ichi Mito | } |
| 86 | else {
|
||
| 87 | # array is not in action |
||
| 88 | 760b14f5 | Ken-ichi Mito | $action = 'idle'; |
| 89 | 6284302a | Ken-ichi Mito | $minute = ''; |
| 90 | 2670e4dc | Ken-ichi Mito | unshift(@text, $line); |
| 91 | } |
||
| 92 | } |
||
| 93 | else {
|
||
| 94 | # skip until first line is found |
||
| 95 | next; |
||
| 96 | } |
||
| 97 | |||
| 98 | 2e0acaca | Ken-ichi Mito | if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
| 99 | print "$dev.label $dev\n"; |
||
| 100 | 6284302a | Ken-ichi Mito | print "$dev.info $type $ro$members\n"; |
| 101 | 2e0acaca | Ken-ichi Mito | # 100: means less than 100 |
| 102 | # Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100. |
||
| 103 | print "$dev.critical 98:\n"; |
||
| 104 | 6284302a | Ken-ichi Mito | print $dev, "_rebuild.label $dev reshape/recovery\n"; |
| 105 | print $dev, "_rebuild.info $action $minute\n"; |
||
| 106 | 2e0acaca | Ken-ichi Mito | # Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100. |
| 107 | print $dev, "_rebuild.critical 98:\n"; |
||
| 108 | print $dev, "_check.label $dev check/resync \n"; |
||
| 109 | 6284302a | Ken-ichi Mito | print $dev, "_check.info $action $minute\n"; |
| 110 | bbec1ffb | Dobrica Pavlinusic | print $dev, "_failed.label $dev failed disks \n"; |
| 111 | print $dev, "_failed.info $action $minute\n"; |
||
| 112 | print $dev, "_failed.critical 0:0\n"; |
||
| 113 | 2e0acaca | Ken-ichi Mito | } else {
|
| 114 | my $pct = 100 * $nact / $nmem; |
||
| 115 | my $rpct = 100; |
||
| 116 | 760b14f5 | Ken-ichi Mito | my $cpct = 100; |
| 117 | if ($action =~ /reshape|recovery/) {
|
||
| 118 | $rpct = $proc; |
||
| 119 | $cpct = 0; # check/resync is not done |
||
| 120 | 2e0acaca | Ken-ichi Mito | } |
| 121 | 760b14f5 | Ken-ichi Mito | elsif ($action =~ /check|resync/) {
|
| 122 | if ($proc < 0) {
|
||
| 123 | # array is on DELAYED or PENDING, further info is unknown |
||
| 124 | $rpct = 0; |
||
| 125 | $cpct = 0; |
||
| 126 | } |
||
| 127 | else {
|
||
| 128 | # reshape/recovery was done, $rpct => 100 |
||
| 129 | $cpct = $proc; |
||
| 130 | } |
||
| 131 | 2e0acaca | Ken-ichi Mito | } |
| 132 | 760b14f5 | Ken-ichi Mito | |
| 133 | 2e0acaca | Ken-ichi Mito | print "$dev.value $pct\n"; |
| 134 | print $dev, "_rebuild.value $rpct\n"; |
||
| 135 | print $dev, "_check.value $cpct\n"; |
||
| 136 | bbec1ffb | Dobrica Pavlinusic | print $dev, "_failed.value $failed\n"; |
| 137 | 2e0acaca | Ken-ichi Mito | } |
| 138 | 6e292519 | Nathan Rutman | } |
| 139 | |||
| 140 | exit 0; |
