-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.sh
More file actions
144 lines (116 loc) · 4.6 KB
/
Copy pathmonitor.sh
File metadata and controls
144 lines (116 loc) · 4.6 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#will do the compress every ~240 x 15 or 3600 seconds (1hour)
COUNTTILLZIP=240
SLEEPTIME=15
trap onExit INT SIGHUP SIGINT SIGTERM
function onExit() {
clear
echo "Exit Trap Received"
echo "Generating final tgz monitor-$starttime-final.tgz"
sar -A > sar-output.txt
tar cvzf "monitor-$starttime-final.tgz" *-output.txt /var/lib/xms/meters/rrd /var/log/messages &> /dev/null
echo 'Clearing temp files'
rm -f tmptop.txt
rm -f tmpps.txt
rm -f sar-output.txt
rm -f top-output.txt
rm -f ps-output.txt
rm -f meters-output.txt
rm -f topthreads-output.txt
rm -f tmp-network.txt
echo -e "Cleanup complete!\n"
echo -e "Exiting\n\n"
exit
}
#Put here anything that should be done once per script run
#start network capture
# Comment out line with tcpdump if you don't want network tracing
echo -e "Starting background network trace for 4xx and 5xx errors\n"
rm -f tmp-network.txt
tcpdump -i any -v port 5060 | grep -P "SIP/2.0 [4|5]" > tmp-network.txt &
while true
do
LOOPCOUNTER=0
#clean up the temp files used as old ones are no saved in tgz
echo 'Clearing temp files'
rm -f tmptop.txt
rm -f tmpps.txt
rm -f top-output.txt
rm -f ps-output.txt
rm -f meters-output.txt
rm -f topthreads-output.txt
starttime=`date +"%y_%m_%d-%H_%M_%S.%3N"`
hostname=`hostname`
while [ $LOOPCOUNTER -lt $COUNTTILLZIP ]; do
let LOOPCOUNTER=LOOPCOUNTER+1
clear
looptimestamp=`date +"%y-%m-%d_%H:%M:%S.%3N"`
echo -e $looptimestamp "-" $hostname [$LOOPCOUNTER out of $COUNTTILLZIP]"\n"
echo -e "\nDisk/Mem Usage:"
free -m
#echo -e "\n"
# df
#echo -e "\n\n\nUptime:" `uptime`
#echo -e "\nXMS Cache file count:"
#echo `ls -l /var/cache/xms/http/xmserver/ | wc -l`
top -b -n 1 > tmptop.txt
echo -e $looptimestamp stamp "----------------" > tmpps.txt
ps -A -Lo %cpu,pid,lwp,comm=,args >> tmpps.txt
echo -e "\n\nCPU Intensive Threads:"
grep -P '^ *[0-9][0-9][0-9]\.' tmpps.txt
grep -P '^ *[4-9][0-9]\.' tmpps.txt
echo -e "\n\nTop Info:"
grep Cpu tmptop.txt
grep Mem: tmptop.txt
grep Swap: tmptop.txt
echo -e "\n"
grep PID tmptop.txt
grep ssp tmptop.txt
grep appmanager tmptop.txt
grep xmserver tmptop.txt
#these can be commended out based on tech used
grep msml tmptop.txt
grep vxml tmptop.txt
grep rest tmptop.txt
grep netann tmptop.txt
grep httpclient tmptop.txt
#used by mrb/lb
# grep java tmptop.txt
#Alternatively you can use
#top -n 1 -b | head -20
echo -e "\n\nMeters(if available):"
grep xmsRtpSessions /var/lib/xms/meters/currentValue.txt
grep xmsSignalingSessions /var/lib/xms/meters/currentValue.txt
grep calls.active /var/lib/xms/meters/currentValue.txt
grep xmsMediaTransactions /var/lib/xms/meters/currentValue.txt
# grep xmsLicenseUsage /var/lib/xms/meters/currentValue.txt
# mpstat -P ALL 1 | tee mpstats.txt
if [[ -f tmp-network.txt ]] ;
then
echo -e "\n\nNetwork Error count:" `cat tmp-network.txt | wc -l ` "\n"
#cat tmp-network.txt >> networkerror-output.txt
cat /dev/null > tmp-network.txt
fi
echo -e "\n$looptimestamp-$hostname\n" >> top-output.txt
cat tmptop.txt >> top-output.txt
echo -e "\n$looptimestamp-$hostname\n" >> ps-output.txt
cat tmpps.txt >> ps-output.txt
echo -e "\n$looptimestamp-$hostname\n" >> meters-output.txt
cat /var/lib/xms/meters/currentValue.txt >> meters-output.txt
echo -e "\n$looptimestamp-$hostname\n" >> topthreads-output.txt
top -b -n 1 -H >> topthreads-output.txt
## additional activites or spy can be done here such as watching messagefile or netcap for 15 seconds or looking for errors to print
#timeout $SLEEPTIME tail -F -n0 tmp-network.txt
#timeout $SLEEPTIME ./scripttorunfortime.sh
echo -e "\n\n"
sleep $SLEEPTIME
rm -f tmptop.txt
rm -f tmpps.txt
done
##put all things there that need to be gathered once per compress loop
sar -A > sar-output.txt
tar cvzf "monitor-$starttime.tgz" *-output.txt /var/lib/xms/meters/rrd /var/log/messages
#delete files over 7 days old
find . -name 'monitor-*.tgz' -mtime +7 -delete
done
onExit