check_lvmthin
changeset 0 0c11e5586312
child 1 3229a6d2b9c8
equal deleted inserted replaced
-1:000000000000 0:0c11e5586312
       
     1 #!/bin/sh -e
       
     2 
       
     3 ME=$(basename $0)
       
     4 echo $ME
       
     5 NAME='LVMTHIN'
       
     6 E=3
       
     7 INFO=
       
     8 PERFDATA=
       
     9 
       
    10 lvsresults=$(mktemp /tmp/$ME.XXX)
       
    11 
       
    12 cleanup() {
       
    13     [ -n "$lvsresults" ] && rm $lvsresults;
       
    14 }
       
    15 
       
    16 nagiosexit() {
       
    17     local STATUS='UNKNOWN'
       
    18     if [ $E = '2' ]; then STATUS='CRITICAL'
       
    19     elif [ $E = '1' ]; then STATUS='WARNING'
       
    20     elif [ $E = '0' ]; then STATUS='OK'
       
    21     fi
       
    22     echo "$NAME $STATUS${INFO:+: ${INFO}}${PERFDATA:+|$PERFDATA}"
       
    23     exit $E
       
    24 }
       
    25 
       
    26 trap 'trap - EXIT; cleanup; nagiosexit $E' INT QUIT TERM EXIT
       
    27 
       
    28 die() {
       
    29     INFO="$@"
       
    30     exit 3
       
    31 }
       
    32 
       
    33 parse_lvs() {
       
    34     results=$1
       
    35     label=$2
       
    36     while read vg lv u; do
       
    37         addinfo=
       
    38         if [ "$u" '>' "$C" ]; then
       
    39             E=2
       
    40             addinfo='yes'
       
    41         elif [ "$u" '>' "$W" ]; then
       
    42             [ $E != '2' ] && E=1
       
    43             addinfo='yes'
       
    44         fi 
       
    45         [ -n "$addinfo" ] && INFO="${INFO:+${INFO}; }$vg/$lv$label $u%"
       
    46         PERFDATA="${PERFDATA:+${PERFDATA} }$vg/$lv$label=$u%;$W%;$C%;;"
       
    47     done <$results
       
    48 }
       
    49 
       
    50 W='80.00'
       
    51 C='90.00'
       
    52 T=
       
    53 P=
       
    54 
       
    55 while getopts "hm?c:p:t:w:" opt; do
       
    56   case $opt in
       
    57     h|\?)
       
    58         cleanup; exec pod2usage -verbose 1 -exit 0 $0
       
    59         ;;
       
    60     m)
       
    61         cleanup; exec pod2usage -verbose 3 -exit 0 $0
       
    62         ;;
       
    63     c)
       
    64         C="$OPTARG"
       
    65         ;;
       
    66     p)
       
    67         P="$P $OPTARG"
       
    68         ;;
       
    69     t)
       
    70         T=$T $OPTARG
       
    71         ;;
       
    72     w)
       
    73         W=$OPTARG
       
    74         ;;
       
    75   esac
       
    76 done
       
    77 shift $((OPTIND-1))
       
    78 
       
    79 lvs --noheadings -S 'segtype=thin||segtype=thin-pool' -o vg_name,lv_name,data_percent $T $P >$lvsresults; parse_lvs $lvsresults
       
    80 lvs --noheadings -S 'segtype=thin-pool' -o vg_name,lv_name,metadata_percent $P >$lvsresults; parse_lvs $lvsresults '(meta)'
       
    81 
       
    82 [ $E = '3' ] && E=0
       
    83 exit $E
       
    84 
       
    85 : <<EOP
       
    86 
       
    87 =encoding utf8
       
    88 
       
    89 =pod
       
    90 
       
    91 =head1 NAME
       
    92 
       
    93 check_lvmthin - check usage of thin provisioned logical volumes (lvm)
       
    94 
       
    95 =head1 SYNOPSIS
       
    96 
       
    97 check_lvmthin [-t volume] [-p volume]
       
    98 
       
    99 check_lvmthin -h|-?|-m
       
   100 
       
   101 =head1 DESCRIPTION
       
   102 
       
   103 This script checks the usage of thin provisioned logical volumes.
       
   104 
       
   105 =head1 OPTIONS
       
   106 
       
   107 =over
       
   108 
       
   109 =item B<-h|-?>
       
   110 
       
   111 Display help.
       
   112 
       
   113 =item B<-m>
       
   114 
       
   115 Display man page.
       
   116 
       
   117 =item B<-c> I<threshold>
       
   118 
       
   119 Exit with status 'CRITICAL' if any checked volume uses more than I<threshold> percent of its size.
       
   120 
       
   121 =item B<-t> I<thinlv>
       
   122 
       
   123 check usage of thin provisioned logical volume I<thinlv>.
       
   124 
       
   125 =item B<-p> I<poollv>
       
   126 
       
   127 check data and metadata usage of pool volume I<poollv>.
       
   128 
       
   129 =item B<-w> I<threshold>
       
   130 
       
   131 Exit with status 'WARNING' if any checked volume uses more than I<threshold> percent of its size.
       
   132 
       
   133 =back
       
   134 
       
   135 I<thinlv> and I<poollv> should be given as names understood by lvs. thresholds should be given in decimal notation with 2 positions after the decimal point.
       
   136 
       
   137 =head1 EXAMPLE
       
   138 
       
   139 check_lvmthin -w 76.54 -t vg/lv
       
   140 
       
   141 =head1 AUTHOR
       
   142 
       
   143 Matthias Förste <foerste@schlittermann.de>
       
   144 
       
   145 =cut
       
   146 
       
   147 EOP