Last active
July 21, 2022 20:57
-
-
Save arpitjindal97/c60e78169356ad09a4417c2287f0f0d4 to your computer and use it in GitHub Desktop.
Parse file.csv generated by K6 (load generation tool)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This script is used to parse file.csv emited by k6 tool | |
## Run this script using below commands: | |
## bash parse_k6.sh | |
## bash parse_k6.sh ping | |
## bash parse_k6.sh allow | |
## bash parse_k6.sh filter | |
# Scenario | |
# if omitted will process all | |
api="$1" | |
echo "Stats for $api Scenario" | |
echo "" | |
echo "---- Total Requests ----" | |
echo -n "Mean: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{sum+=$3;count++} END{print sum/count}' | |
echo -n "Minimum: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{print $3}' | sort -g | head -n 1 | |
echo -n "Median: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.5 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo -n "Maximum: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{print $3}' | sort -g | tail -n 1 | |
echo -n "90th Percentile: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.9 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo -n "95th Percentile: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.95 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo -n "99th Percentile: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.99 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo "" | |
echo -n "Failed Requests: " | |
grep -E 'http_req_duration' file.csv | grep false -c | |
echo "" | |
echo "---- Passed Requests ----" | |
echo -n "Mean: " | |
grep -E 'http_req_duration' file.csv | grep -v false |grep "$api" | awk -F ',' '{sum+=$3;count++} END{print sum/count}' | |
echo -n "Minimum: " | |
grep -E 'http_req_duration' file.csv | grep -v false | grep "$api" | awk -F ',' '{print $3}' | sort -g | head -n 1 | |
echo -n "Median: " | |
grep -E 'http_req_duration' file.csv | grep -v false | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.5 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo -n "Maximum: " | |
grep -E 'http_req_duration' file.csv | grep -v false | grep "$api" | awk -F ',' '{print $3}' | sort -g | tail -n 1 | |
echo -n "90th Percentile: " | |
grep -E 'http_req_duration' file.csv | grep -v false | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.9 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo -n "95th Percentile: " | |
grep -E 'http_req_duration' file.csv | grep -v false | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.95 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo -n "99th Percentile: " | |
grep -E 'http_req_duration' file.csv | grep -v false | grep "$api" | awk -F ',' '{print $3}' | sort -g | awk '{all[NR] = $1} END{val=(NR*0.99 - 0.5);x=int(val);print all[(x==val||x>val)?x:x+1]}' | |
echo "----------------------" | |
echo "" | |
echo -n "Total API Hit: " | |
grep -E 'http_req_duration' file.csv | grep "$api" -c | |
echo -n "Average TPS: " | |
grep -E 'http_req_duration' file.csv | grep "$api" | awk -F ',' '{print $2}' | uniq -c | awk '{sum+=$1;count++}END{print sum/(count-1)}' | |
echo "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Sample script to generate distributed load on 3 API's | |
Total VU = 80 | |
- 24 on ping | |
- 24 on allow | |
- 32 on filter | |
Run k6 using below command: | |
k6 run script.js --out csv --summary-trend-stats "avg,min,med,max,p(90),p(95),p(99)" | |
*/ | |
import http from 'k6/http'; | |
import { sleep } from 'k6'; | |
export const options = { | |
discardResponseBodies: true, | |
scenarios: { | |
ping: { | |
executor: 'constant-vus', | |
exec: 'ping', | |
vus: 80 * 30 / 100, | |
duration: '30s', | |
}, | |
allow: { | |
executor: 'constant-vus', | |
exec: 'allow', | |
vus: 80 * 30 / 100, | |
duration: '30s', | |
}, | |
filter: { | |
executor: 'constant-vus', | |
exec: 'filter', | |
vus: 80 * 40 / 100, | |
duration: '30s', | |
}, | |
}, | |
}; | |
export function ping() { | |
http.get('https://google.com/'); | |
} | |
export function filter() { | |
http.get('https://microsoft.com/'); | |
} | |
export function allow() { | |
http.get('https://amazon.com'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment