forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovs-monitor
executable file
·127 lines (106 loc) · 3.35 KB
/
ovs-monitor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
# Copyright (C) 2008, 2009 Nicira Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
OPENFLOWD_PID=/var/run/ovs-openflowd.pid
OPENFLOWD_SOCK=/var/run/ovs-openflowd.mgmt
LOG_FILE=/var/log/openflow/monitor
INTERVAL=1
FAIL_THRESH=3
usage() {
echo usage: $0 options
echo
echo "OPTIONS:"
echo " -h Show this message"
echo " -p PID file for ovs-openflowd (default: $OPENFLOWD_PID)"
echo " -s Unix socket for ovs-openflowd (default: $OPENFLOWD_SOCK)"
echo " -l File to log messages (default: $LOG_FILE)"
echo " -i Interval to send probes in seconds (default: $INTERVAL)"
echo " -c Number of failed probes before reboot (default: $FAIL_THRESH)"
}
log() {
echo `date +"%b %d %X"`:$1
echo `date +"%b %d %X"`:$1 >> $LOG_FILE
}
while getopts "hp:s:l:i:c:" OPTION; do
case $OPTION in
h)
usage
exit 1
;;
p)
OPENFLOWD_PID=$OPTARG
;;
s)
OPENFLOWD_SOCK=$OPTARG
;;
l)
LOG_FILE=$OPTARG
;;
i)
INTERVAL=$OPTARG
;;
c)
FAIL_THRESH=$OPTARG
;;
*)
echo "Unknown option: ${OPTION}"
esac
done
if [ ! -f $OPENFLOWD_PID ]; then
log "No ovs-openflowd pid file: ${OPENFLOWD_PID}"
echo "No ovs-openflowd pid file: ${OPENFLOWD_PID}"
fi
if [ ! -S $OPENFLOWD_SOCK ]; then
log "No ovs-openflowd sock file: ${OPENFLOWD_SOCK}"
echo "No ovs-openflowd sock file: ${OPENFLOWD_SOCK}"
fi
if [ ! -d `dirname $LOG_FILE` ]; then
mkdir -p `dirname $LOG_FILE`
fi
let DP_DOWN=0
let OPENFLOWD_DOWN=0
log "===== Starting Monitor ===="
while `/bin/true`; do
# Only check for liveness if ovs-openflowd's PID file exists. The PID
# file is removed when ovs-openflowd is brought down gracefully.
if [ -f $OPENFLOWD_PID ]; then
pid=`cat $OPENFLOWD_PID`
if [ -d /proc/$pid ]; then
# Check if the ovs-openflowd and datapath still can communicate
if [ -S $OPENFLOWD_SOCK ]; then
ovs-ofctl probe -t 2 unix:$OPENFLOWD_SOCK
if [ $? -ne 0 ]; then
log "datapath probe failed"
let DP_DOWN++
else
let DP_DOWN=0
fi
fi
let OPENFLOWD_DOWN=0
else
log "ovs-openflowd probe failed"
let OPENFLOWD_DOWN++
fi
fi
if [ $OPENFLOWD_DOWN -ge $FAIL_THRESH ]; then
log "Failed to probe ovs-openflowd after ${OPENFLOWD_DOWN} tries...rebooting!"
reboot
fi
if [ $DP_DOWN -ge $FAIL_THRESH ]; then
log "Failed to probe datapath after ${DP_DOWN} tries...rebooting!"
reboot
fi
sleep $INTERVAL
done