-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstalk
More file actions
executable file
·50 lines (46 loc) · 1.81 KB
/
stalk
File metadata and controls
executable file
·50 lines (46 loc) · 1.81 KB
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
#!/bin/bash
# This program is part of Aspersa (http://code.google.com/p/aspersa/)
# TODO: advise if running non-root
# TODO: never use ~, always use ${HOME}
# ########################################################################
# A script to watch MySQL and run the 'collect' program when some condition
# becomes true. By default, it watches for a too-many-connections condition.
# This is a good script to run in a screen session. It's separate from the
# 'collect' script because that lets you change 'collect' without stopping
# and restarting this one.
#
# The name 'stalk' is because 'watch' is already taken, and 'stalk' is fun.
#
# Author: Baron Schwartz
# ########################################################################
# ########################################################################
# Configuration settings.
# ########################################################################
# This is the max number of connections we want to tolerate. You can pass this
# in as the first command-line option if you want.
THREADS=${1:-100}
# This is the location of the 'collect' script.
COLLECT="${HOME}/bin/collect";
# This is the interval between checks; pass it as the 2nd command-line option.
SLEEP=${2:-30}
# This is the thing to check for. You can pass this as the third option.
VARIABLE=${3:-Threads_connected}
while true; do
date
threads=""
threads=$(mysqladmin ext | grep ${VARIABLE} | awk '{print $4}');
execute=no
if [ -z "${threads}" ]; then
execute="yes" # Oops, couldn't connect, maybe max_connections problem.
elif [ ${threads} -gt $THREADS ]; then
execute="yes"
fi
if [ "${execute}" = "yes" ]; then
echo "Executing collection script"
${COLLECT}
echo "sleeping a while to avoid DOS attack"
sleep 600
else
sleep ${SLEEP}
fi
done