Created
April 8, 2017 20:24
-
-
Save ahadsheriff/1c820c63f544522a46c0c9a9bd490a44 to your computer and use it in GitHub Desktop.
Python script to load test a website, grab the important information from the load tester, and output the information to a text file.
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
import datetime | |
import os | |
# Local Website: http://127.0.0.1/var/website/html | |
website = str(input("Enter the URL of the website you want to test: ")) | |
os.system('ab -n 1000 -c 5 '+ website + ' > LoadTest.txt') | |
infile = 'LoadTest.txt' | |
important = [] | |
keep_phrases = ["Benchmarking", "Document Path", "Complete requests", "Time per request", "Transfer rate"] | |
with open(infile) as f: | |
f = f.readlines() | |
for line in f: | |
for phrase in keep_phrases: | |
if phrase in line: | |
important.append(line) | |
break | |
hostText = important[0] | |
hostHead = hostText.partition(' (') | |
need = hostHead[0] | |
query = need | |
stopwords = ['benchmarking'] | |
querywords = query.split() | |
resultwords = [word for word in querywords if word.lower() not in stopwords] | |
host = ' '.join(resultwords) | |
pathText = important[1] | |
pathHead = pathText.partition(': ') | |
path = (pathHead[2].lstrip().rstrip("\r\n")) | |
hitsText = important[2] | |
hitsHead = hitsText.partition(': ') | |
hits = (hitsHead[2].lstrip().rstrip("\r\n")) | |
reqText = important[3] | |
reqHead = reqText.partition(': ') | |
req = (reqHead[2].lstrip().rstrip("\r\n")) | |
transText = important[5] | |
transHead = transText.partition(': ') | |
trans = (transHead[2].lstrip().rstrip("\r\n")) | |
month = datetime.datetime.now().month | |
day = datetime.datetime.now().day | |
year = datetime.datetime.now().year | |
time = datetime.datetime.now().time() | |
lineBreak = "-----------------------------------------------------------------------\n" | |
file = open("loadTestReport.txt", "w") | |
file.write(lineBreak) | |
file.write("Weblog report for " + host + path + " by Ahad Sheriff\n") | |
file.write(lineBreak) | |
file.write("Report was taken on " + str(month) + "/" + str(day) + "/" + str(year) + " at " + str(time) + "\n") | |
file.write(lineBreak) | |
file.write("There were " + hits + " hits. Request time was: " + req + "\n") | |
file.write(lineBreak) | |
file.write("Transfer rate: " + trans + "\n") | |
file.write(lineBreak) | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment