Whamcloud - gitweb
LU-6698 kernel: kernel update RHEL 6.6 [2.6.32-504.23.4.el6]
[fs/lustre-release.git] / lustre / scripts / lc_mon
1 #!/bin/sh
2
3 # Given one or more Lustre objects, create a mon configuration file
4 # naming the mon watches based on the Lustre object names 
5 # For each Lustre object, the script will create two mon watches
6 # The first watch sets a trap, and the second watch clears the 
7 # trap if Lustre is healthy.
8
9 # This may be more fun in Perl due to the need to support a list
10 # of objects
11
12 # (plus we could use a Perl format for this goop)
13
14 MONBASEDIR=${MONBASEDIR:-/usr/local/lib/mon}
15 MONCFGDIR=${MONCFGDIR:-/etc/mon}
16 TD=`date +%y_%m%d_%S`
17 TMPMONCFG=${TD}-mon.cfg
18 # Determines how often we will check Lustre health
19 CHECKINTERVAL="3m"
20 # Determines how quickly we must clear the trap
21 TRAPINTERVAL="6m"
22 ALERTSCRIPT=${ALERTSCRIPT:-"fail_lustre.alert"}
23 TRAPSCRIPT=${TRAPSCRIPT:-"lustre.mon.trap"}
24
25 # We will assume all inputs are Lustre objects
26 # file locations and timeouts correct to taste
27 # Correct to taste
28 print_header() {
29     cat >> $TMPMONCFG <<-EOF
30         cfbasedir     = $MONCFGDIR
31         alertdir      = $MONBASEDIR/alert.d
32         mondir        = $MONBASEDIR/mon.d
33         statedir      = $MONBASEDIR/state.d
34         logdir        = $MONBASEDIR/log.d
35         dtlogfile     = $MONBASEDIR/log.d/downtime.log
36         maxprocs      = 20 
37         histlength    = 100 
38         randstart     = 60s
39         authtype      = getpwnam
40 EOF
41 }
42
43 # Tabs should be preserved in the config file
44 # $1 object name
45 # we do not set a period, it is assumed monitor is always active
46
47 print_trap_rec() {
48     cat >> $TMPMONCFG <<EOF
49 #
50 watch ${1}-obj
51     service ${1}_ser
52     description triggers heartbeat failure if trap springs on $1
53     traptimeout $TRAPINTERVAL
54     period 
55         alert $ALERTSCRIPT
56
57 # end ${1}-obj
58
59 EOF
60
61 }
62
63 print_trap_send() {
64     cat >> $TMPMONCFG <<EOF
65 #
66 watch ${1}-mon
67     service ${1}_mon_ser
68     description clears trap for $1
69     interval $CHECKINTERVAL
70     monitor $TRAPSCRIPT ${1}-obj ${1}_ser ${1}
71     period
72         alert $ALERTSCRIPT
73 # end ${1}-mon
74 EOF
75
76 }
77
78 usage() {
79     echo "$0 -n <node> -n <node> -o <Lustre object> -o <Lustre object>...."
80     echo "Creates the /etc/mon/mon.cf file to monitor Lustre objects"
81     exit 1
82 }
83
84
85 # Start of script
86
87 if [ $# -eq 0 ];then
88     usage
89 fi
90
91 # This script should work for any number of hosts
92
93 HOSTCNT=0
94 OBJCNT=0
95
96 declare -a HOSTS
97 declare -a OBJS
98
99 while getopts "n:o:" opt; do
100     case $opt in 
101         n) HOSTS[HOSTCNT]=$OPTARG
102             HOSTCNT=$(( HOSTCNT + 1 ))
103             ;;
104         o) OBJS[OBJCNT]=$OPTARG
105             OBJCNT=$(( OBJCNT + 1 ))
106             ;;
107         *) usage
108             ;;
109     esac
110 done
111
112 echo "Found $HOSTCNT hosts"
113 echo "Found $OBJCNT Lustre objects"
114
115 # First create the host groups
116 # we assume 
117 # each object will have two watches defined
118 # each object hostgroup will have all objects
119
120 # Create the file with the declared goop
121 print_header
122
123 for obj in ${OBJS[@]}
124 do
125     echo "hostgroup ${obj}-obj ${HOSTS[@]}" >> $TMPMONCFG
126     echo "hostgroup ${obj}-mon ${HOSTS[@]}" >> $TMPMONCFG
127     echo "#" >> $TMPMONCFG
128 done
129     
130 # create the monitors
131
132 for obj in ${OBJS[@]}
133 do
134     print_trap_send $obj
135     print_trap_rec $obj
136 done
137
138 echo "Mon config completed - new mon config is $TMPMONCFG"
139 exit 0