Revise a print error for test_service script
[iec.git] / src / tools / test_service_latency.sh
1 set -e
2
3 localIP=$(ip route show default | cut -d " " -f 9)
4 echo "localIP:"$localIP
5 echo ""
6
7 if [ "x${1}" == "x" ]; then
8 echo "No node IP defined, uses the local IP instead."
9 fi
10
11 nodeIP=$localIP
12 aNum=1000
13
14 display_help () {
15   echo "Usage:"
16   echo " "
17   echo "Please input the nodeIP and access number"
18 }
19
20
21 ARGS=`getopt -a -o s:n:c:p:k::h:: -l nodeIP:,number:,serviceIP:,nodePort:,nodeOnly::,help:: -- "$@"`
22 eval set -- "${ARGS}"
23 while true
24 do
25         case "$1" in
26         -s|--nodeIP)
27                 nodeIP="$2"
28                 echo "nodeIP=$2"
29                 shift
30                 ;;
31         -n|--number)
32                 aNum="$2"
33                 echo "access number=$2"
34                 shift
35                 ;;
36         -c|--serviceIP)
37                 svcIP="$2"
38                 echo "Service IP=$2"
39                 shift
40                 ;;
41         -p|--nodePort)
42                 nodePort="$2"
43                 echo "nodePort=$2"
44                 shift
45                 ;;
46         -k|--nodeOnly)
47                 nodeOnly="true"
48                 echo "Ignore accessing service IP test."
49                 echo "nodeOnly=true"
50                 ;;
51         -h|--help)
52                 echo "this is help case"
53                 display_help
54                 exit 0
55                 ;;
56         --)
57                 echo ""
58                 echo "Use default args, now do the test:"
59                 echo ""
60                 shift
61                 break
62                 ;;
63         esac
64 shift
65 done
66
67
68 if [[ "x${svcIP}" == "x"  &&  ${onlyNode} != "true" ]]; then
69   echo "No service IP defined, try to find locally:"
70   svcIP=$(kubectl get svc | grep nginx |grep -i "nodeport" | awk -F'[ ]+' '{print $3}')
71   echo "Service IP:"$svcIP
72 fi
73
74 if [ "x${nodePort}" == "x" ]; then
75   echo "No nodePort defined, try to find locally:"
76   nodePort=$(kubectl get svc | grep nginx |grep -i "nodeport" | awk -F'[ ]+' '{print $5}' | cut -d ":" -f 2 |cut -d "/" -f 1)
77   echo "NodePort:"$nodePort
78 fi
79
80 accessNum=$((aNum + 0))
81 START=1
82 END=$aNum
83
84 if [ "x${nodeOnly}" != "xtrue" ]; then
85   echo "Now access the service IP $svcIP:80, $aNum times, time total:"
86   for (( c=$START; c<=$END; c++))
87   do
88     curl -w "%{time_total}\n" -o /dev/null -s http://$svcIP
89   done | jq -s add/length
90   echo "Now access the service IP $svcIP:80, $aNum times, time connect:"
91   for (( c=$START; c<=$END; c++))
92   do
93     curl -w "%{time_connect}\n" -o /dev/null -s http://$svcIP
94   done | jq -s add/length
95 fi
96
97 echo ""
98 echo "Now access the $nodeIP:$nodePort, $aNum times, time total:"
99 for (( c=$START; c<=$END; c++))
100 do
101     curl -w "%{time_total}\n" -o /dev/null -s $nodeIP:$nodePort
102 done | jq -s add/length
103 echo "Now access the $nodeIP:$nodePort, $aNum times, time connect:"
104 for (( c=$START; c<=$END; c++))
105 do
106     curl -w "%{time_connect}\n" -o /dev/null -s $nodeIP:$nodePort
107 done | jq -s add/length