-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcmonalyser.sh
executable file
·84 lines (65 loc) · 1.86 KB
/
cmonalyser.sh
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
#!/usr/bin/env bash
# Copyright 2010 Alexandre Gomes (alegomes at gmail)
#
# This file is part of Catalina Monitor (C'Mon) Suite.
#
# C'Mon is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# C'Mon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with C'Mon. If not, see <http://www.gnu.org/licenses/>.
IFS=$'\n'
function usage() {
echo
echo 'Script that logs machine load spikes with a running Tomcat'
echo
echo 'Usage: cmonalyser.sh <arquivo_de_log> <load_de_referencia>'
echo
echo 'e.g.: ./cmonalyser.sh /var/log/catalinastat.20101109.log 15'
echo
exit -1
}
function analyse() {
clear
echo
echo "Getting load > $THRESHOLD from $FILE "
echo
echo -e "\033[s"
echo
c=0
load_count=0
symbol=(q w e r t y u i o p a s d f g h j k l z x c v b n m)
for line in $(cat $FILE); do
echo -en "\033[u "
echo -en "\033[2;70H ${symbol[`expr $c % 26`]}"
echo -en "\033[s"
((c = c + 1))
metrics=$(echo $line | grep -v Load )
if [ -n "${metrics}" ]; then
load=$(echo $metrics | awk '{print $3}')
overloaded=$(echo "$load > ${THRESHOLD}" | bc)
if [[ "$overloaded" -eq "1" ]]; then
echo -e "$line" >> $TEMP
fi
fi
done
clear
cat $TEMP
echo
echo "Registries 'load > $THRESHOLD' saved in $TEMP"
echo
}
if [[ -z "$1" || -z "$2" ]]; then
usage
fi
FILE=$1
THRESHOLD=$2
TEMP="/var/log/${FILE:9}.$(hostname).gt${THRESHOLD}"
analyse