forked from aqingsao/nana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbalance.sh
47 lines (43 loc) · 1.04 KB
/
nbalance.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
#!/bin/sh
function printHelp()
{
echo "Usage:"
echo "-n: count of lines to show"
echo "-h: usage"
echo ""
}
lineCount=10
while getopts "hn:" optname
do
case "$optname" in
"n")
lineCount=$OPTARG
;;
"h")
printHelp
exit 1
;;
*)
printHelp
exit 1
;;
\?)
echo "Invalid option -$OPTARG"
printHelp
exit 1
;;
esac
done
file="${@: -1}"
if [ "$file" = "" ]; then
echo "please provide an Nginx log file"
exit 1;
fi
if [ ! -f $file ]; then
echo "File $file does not exist";
exit 1;
fi
echo ""
echo "[Busiest]"
echo "Request Count/ Percentage/ Response Time/req \t upstream server"
less $file | awk '{upServer=$13;upTime=$12;if(upServer == "-"){upServer="Nginx"};if(upTime == "-"){upTime=0};upTimes[upServer]+=upTime;count[upServer]++;totalCount++;} END{for(server in upTimes){printf("%s %s%s %sms %s\n", count[server], count[server]/totalCount * 100, "%", 1000*upTimes[server]/count[server], server)}}' | sort -nr