aboutsummaryrefslogtreecommitdiffstats
path: root/testsuites/stability/src/main/resources/generate_performance_report.sh
blob: f8745e179d1904723d351377043a23df14c9686b (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash

# Copyright (C) 2020 AT&T. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# The aim of this script is to collect performance metric for policies running in PDP-D.
#
# Pre-requisites:
#
# Run the JMeter Stability test plan on the PDP-D for at least few hours so that enough samples
# are collected and used for performance calculation.
#
# Recommendation:
# Run for 72 hours
#
# How to run:
# 1: Copy this script to drools container
# 2: Pass following parameters to run the script
#    - log-dir : the complete directory location of audit.log file.
#    - wait : the wait time configured in JMeter test plan. (in Guilin Release is no wait time)
#
# Sample command for running the script: ./generate_performance_report -l /var/log/onap/policy/pdpd -w 500
# Note: -h or --help can be used to display details about input parameters.
#
# How it works
# The script will parse the audit.log file at the specified location and fetch the running time of each policy.
# Take enough samples and then calculate the average time taken for policies to complete.

usage()
{
_msg_="$@"
scriptname=$(basename $0)

cat<<-EOF

Command Arguments:

-l, --log-dir
 Mandatory argument. Directory location of audit logs.

-w, --wait
 Mandatory argument.  Wait time between onset and appc for vCPE and vFW (in milliseconds)

-h, --help
 Optional argument.  Display this usage.

EOF
exit 1

}

process_vCPE_FAIL() {
 # vCPE use case
 vcpe0_perf_list=($(ls -lrth $LOG_DIR/audit.* | awk '{print $9}'| xargs -n1 zgrep ControlLoop-vCPE-Fail | grep "FINAL.FAILURE.ACCEPTED" | awk -F'|' '{print $7 }'| tail -200000))

 vcpe0Total=0
 vcpe0Sum=0
 vcpe0Max=0
 vcpe0Min=10000
 for count in "${vcpe0_perf_list[@]}"
    do
      if [ "$count" -gt "$vcpe0Max" ]; then
              vcpe0Max=$count
      fi
      if [ "$count" -lt "$vcpe0Min" ]; then
              vcpe0Min=$count
      fi
      vcpe0Sum=$(($vcpe0Sum + $count))
      vcpe0Total=$(($vcpe0Total + 1))
    done
 # Multiplying by 2 because stability test waits after onset and abatement
 average=$((($vcpe0Sum / $vcpe0Total)-(2*$WAIT)))
 echo "vCPE Failure cuse case ==> Max: $vcpe0Max, Min: $vcpe0Min, Average: $average ms [samples taken for average: $vcpe0Total]"
}

process_vCPE_OK() {
 # vCPE use case
 vcpe_perf_list=($(ls -lrth $LOG_DIR/audit.* | awk '{print $9}'| xargs -n1 zgrep ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e | grep COMPLETE | grep FINAL | awk -F'|' '{print $7 }' | tail -200000))

 vcpeTotal=0
 vcpeSum=0
 vcpeMax=0
 vcpeMin=10000
 for count in "${vcpe_perf_list[@]}"
    do
      if [ "$count" -gt "$vcpeMax" ]; then
              vcpeMax=$count
      fi
      if [ "$count" -lt "$vcpeMin" ]; then
              vcpeMin=$count
      fi
      vcpeSum=$(($vcpeSum + $count))
      vcpeTotal=$(($vcpeTotal + 1))
    done
 # Multiplying by 2 because stability test waits after onset and abatement
 average=$((($vcpeSum / $vcpeTotal)-(2*$WAIT)))
 echo "vCPE Success cuse case ==> Max: $vcpeMax, Min: $vcpeMin, Average: $average ms [samples taken for average: $vcpeTotal]"
}

process_vFW() {
 # vFirewall use case
 vfw_perf_list=($(ls -lrth $LOG_DIR/audit.* | awk '{print $9}'| xargs -n1 zgrep ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a | grep COMPLETE | grep FINAL | awk -F'|' '{print $7 }' | tail -200000))

 vfwTotal=0
 vfwSum=0
 vfwMax=0
 vfwMin=10000
 for count in "${vfw_perf_list[@]}"
    do
      if [ "$count" -gt "$vfwMax" ]; then
	      vfwMax=$count
      fi
      if [ "$count" -lt "$vfwMin" ]; then
	      vfwMin=$count
      fi
      vfwSum=$(($vfwSum + $count))
      vfwTotal=$(($vfwTotal + 1))
    done
 # Substracting wait as stability test waits after onset
 average=$((($vfwSum / $vfwTotal)-$WAIT))
 echo "vFirewall Success use case => Max: $vfwMax, Min: $vfwMin, Average: $average ms [samples taken for average: $vfwTotal]"
}

process_vDNS_OK() {
 # vDNS use case
 vdns_perf_list=($(ls -lrth $LOG_DIR/audit.* | awk '{print $9}'| xargs -n1 zgrep ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3 | grep COMPLETE | grep FINAL | awk -F'|' '{print $7 }' | tail -200000))

 vdnsTotal=0
 vdnsSum=0
 vdnsMax=0
 vdnsMin=10000
 for count in "${vdns_perf_list[@]}"
     do
        if [ "$count" -gt "$vdnsMax" ]; then
              vdnsMax=$count
       fi
       if [ "$count" -lt "$vdnsMin" ]; then
              vdnsMin=$count
       fi
       vdnsSum=$(($vdnsSum + $count))
       vdnsTotal=$(($vdnsTotal + 1))
     done
 average=$(($vdnsSum / $vdnsTotal))
 echo "vDNS Success use case => Max: $vdnsMax, Min: $vdnsMin, Average: $average ms [samples taken for average: $vdnsTotal]"
}

process_vDNS_FAIL() {
 # vDNS use case
 vdns_perf_list=($(ls -lrth $LOG_DIR/audit.* | awk '{print $9}'| xargs -n1 zgrep ControlLoop-vDNS-Fail | grep "failed to execute the next step" | awk -F'|' '{print $7 }' | tail -200000))

 vdns0Total=0
 vdns0Sum=0
 vdns0Max=0
 vdns0Min=10000
 for count in "${vdns_perf_list[@]}"
     do
        if [ "$count" -gt "$vdns0Max" ]; then
              vdns0Max=$count
       fi
       if [ "$count" -lt "$vdns0Min" ]; then
              vdns0Min=$count
       fi
       vdns0Sum=$(($vdns0Sum + $count))
       vdns0Total=$(($vdns0Total + 1))
     done
 average=$(($vdns0Sum / $vdns0Total))
 echo "vDNS Failure use case => Max: $vdns0Max, Min: $vdns0Min, Average: $average ms [samples taken for average: $vdns0Total]"
}

# Called when script is executed with invalid arguments
invalid_arguments() {
echo "Missing or invalid option(s):"
echo "$@"
echo "Try -help for more information"
   exit 1
}

# Process the arguments passed to the script
process_arguments() {
short_args="hl:w:"
long_args="help,log-dir:wait:"

args=$(getopt -o $short_args -l $long_args -n "$0"  -- "$@"  2>&1 )
[[ $? -ne 0 ]] && invalid_arguments $( echo " $args"| head -1 )
[[ $# -eq 0 ]] && invalid_arguments "No options provided"
eval set -- "$args"
cmd_arg="$0"

while true; do
    case "$1" in
        -l|--log-dir)
          LOG_DIR=$2
          shift 2 ;;
        -w|--wait)
          WAIT=$2
          shift 2 ;;
         -h|--help)
          usage
          exit 0
          ;;
         --)
          shift
          break ;;
         *)
          echo BAD ARGUMENTS # perhaps error
          break ;;
      esac
done

if ! [[ -d $LOG_DIR ]]; then
    echo "$LOG_DIR does not exists" >&2; exit 1
fi

re='^[0-9]+$'
if ! [[ $WAIT =~ $re ]] ; then
    echo "error: WAIT must be number " >&2; exit 1
fi

}


# main body
process_arguments $@
process_vCPE_OK
process_vCPE_FAIL
process_vDNS_OK
process_vDNS_FAIL
process_vFW