Last active
March 31, 2017 16:23
-
-
Save vanclist/d76cf4b3c7e8a88365812e80952603c6 to your computer and use it in GitHub Desktop.
wrk result to HTML on Teamcity
This file contains 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
#!/usr/bin/env bash | |
PROJECTS=(%projects%) | |
USER_NAME=root | |
SERVER_PATH=/opt/some-server/ | |
CONNECTIONS=(1 4 16 64 256 1024) | |
BOOTSTRAP='<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">' | |
JS_LIBS='<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>' | |
# clean up working directory | |
rm -r *.html | |
for PROJECT in "${PROJECTS[@]}" | |
do | |
echo "Starting project $PROJECT:" | |
WRK_REPORT="wrk_${PROJECT}.html" | |
# start server and wait until curl response will be OK (status code 0) | |
ssh -p 22 -n -f ${USER_NAME}@%host% "sh -c 'cd $SERVER_PATH && sbt \";project $PROJECT;run\" &'" | |
loops=0; while [ ${loops} -lt 60 ]; do curl "http://%host%:%port%/%query%" &> /dev/null; [ "$?" = "0" ] && break; loops=$(( $loops + 1 )); sleep 1; done | |
# create report file and put hardcoded html tags and css into it | |
echo "<html><body>$BOOTSTRAP" > ${WRK_REPORT} | |
echo '<head><style type="text/css">' >> ${WRK_REPORT} | |
echo '.panel-heading .accordion-toggle:after {font-family: "Glyphicons Halflings";content: "\e114";float: right;color: grey;}' >> ${WRK_REPORT} | |
echo '.panel-heading .accordion-toggle.collapsed:after {content: "\e080";}' >> ${WRK_REPORT} | |
echo '</style></head>' >> ${WRK_REPORT} | |
echo '<div class="container"><div class="panel-group" id="accordion">' >> ${WRK_REPORT} | |
# main loop | |
for CNT in "${CONNECTIONS[@]}" | |
do | |
echo "Running simulation with $CNT connection(s)" | |
echo '<div class="panel panel-info"><div class="panel-heading"><h4 class="panel-title">' >> ${WRK_REPORT} | |
echo "<a class=\"accordion-toggle\" data-toggle=\"collapse\" data-parent=\"#accordion\" href=\"#collapse$CNT\">$CNT connections</a></h4></div>" >> ${WRK_REPORT} | |
IN=""; if [ "$CNT" == "1" ]; then IN="in"; fi | |
echo "<div id=\"collapse$CNT\" class=\"panel-collapse collapse $IN\"><div class=\"panel-body\"><pre>" >> ${WRK_REPORT} | |
# put raw wrk output inside <pre> tag | |
wrk -t 1 -c ${CNT} -d %duration% 'http://%host%:%port%/%query%' >> ${WRK_REPORT} | |
echo '</pre></div></div></div>' >> ${WRK_REPORT} | |
done | |
# append some jQuery and Bootstrap stuff | |
echo "</div></div>$JS_LIBS</body></html>" >> ${WRK_REPORT} | |
# kill server | |
echo "Stopping server..." | |
ssh -p 2233 -n -f ${USER_NAME}@%host% "sh -c 'pkill java'" | |
echo "Done" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment