forked from moodlehq/moodle-ci-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ad7302
commit c0d752e
Showing
6 changed files
with
311 additions
and
39 deletions.
There are no files selected for viewing
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
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
193 changes: 193 additions & 0 deletions
193
runner/main/modules/docker-jmeter/libraries/recorder.bsf
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import java.io.*; | ||
import java.util.regex.*; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.jmeter.util.JMeterUtils; // http://jakarta.apache.org/jmeter/api/org/apache/jmeter/util/JMeterUtils.html | ||
import org.apache.jmeter.threads.JMeterContext; // http://jakarta.apache.org/jmeter/api/org/apache/jmeter/threads/JMeterContext.html | ||
import org.apache.jmeter.samplers.SampleResult; // http://jakarta.apache.org/jmeter/api/org/apache/jmeter/samplers/SampleResult.html | ||
|
||
MoodleResult(JMeterContext ctx) { | ||
|
||
Integer thread = ctx.getThreadNum(); | ||
SampleResult result = ctx.getPreviousResult(); | ||
|
||
String html = result.getResponseDataAsString(); | ||
|
||
String dbreads = "0"; | ||
Pattern pdbreads = Pattern.compile(".*?DB reads/writes: (\\d+)/\\d+.*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mdbreads = pdbreads.matcher(html); | ||
if (mdbreads.matches()) { | ||
dbreads = mdbreads.group(1); | ||
} | ||
|
||
String dbwritesstr = "0"; | ||
Pattern pdbwrites = Pattern.compile(".*?DB reads/writes: \\d+/(\\d+).*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mdbwrites = pdbwrites.matcher(html); | ||
if (mdbwrites.matches()) { | ||
dbwritesstr = mdbwrites.group(1); | ||
} | ||
Integer dbwrites = Integer.parseInt(dbwritesstr); | ||
|
||
// Adding logs if required. | ||
if (props.get("includelogs") != null) { | ||
Pattern plogwrites = Pattern.compile(".*?Log DB writes (\\d+).*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mlogwrites = plogwrites.matcher(html); | ||
if (mlogwrites.matches()) { | ||
dbwrites = dbwrites + Integer.parseInt(mlogwrites.group(1)); | ||
} | ||
} | ||
|
||
String dbquerytime = "0"; | ||
Pattern pdbquerytime = Pattern.compile(".*?DB queries time: (\\d+(\\.\\d+)?) secs.*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mdbquerytime = pdbquerytime.matcher(html); | ||
if (mdbquerytime.matches()) { | ||
dbquerytime = mdbquerytime.group(1); | ||
} | ||
|
||
String memoryused = "0"; | ||
Pattern pmemoryused = Pattern.compile(".*?RAM: (\\d+(\\.\\d+)?)[^M]*MB.*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mmemoryused = pmemoryused.matcher(html); | ||
if (mmemoryused.matches()) { | ||
memoryused = mmemoryused.group(1); | ||
} | ||
|
||
String filesincluded = "0"; | ||
Pattern pfilesincluded = Pattern.compile(".*?Included (\\d+) files.*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mfilesincluded = pfilesincluded.matcher(html); | ||
if (mfilesincluded.matches()) { | ||
filesincluded = mfilesincluded.group(1); | ||
} | ||
|
||
String serverload = "0"; | ||
Pattern pserverload = Pattern.compile(".*?Load average: (\\d+(\\.\\d+)?).*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mserverload = pserverload.matcher(html); | ||
if (mserverload.matches()) { | ||
serverload = mserverload.group(1); | ||
} | ||
|
||
String sessionsize = "0"; | ||
Pattern psessionsize = Pattern.compile(".*?Session[^:]*: (\\d+(\\.\\d+)? ?[a-zA-Z]*).*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher msessionsize = psessionsize.matcher(html); | ||
if (msessionsize.matches()) { | ||
sessionsize = msessionsize.group(1); | ||
} | ||
|
||
String timeused = "0"; | ||
Pattern ptimeused = Pattern.compile(".*?\"timeused[^\"]*\">(\\d+(\\.\\d+)?) secs.*", Pattern.UNIX_LINES | Pattern.DOTALL); | ||
Matcher mtimeused = ptimeused.matcher(html); | ||
if (mtimeused.matches()) { | ||
timeused = mtimeused.group(1); | ||
} | ||
|
||
// Actual information collected about the sample by jmeter | ||
String username = vars.get("username"); | ||
String name = StringUtils.rightPad(result.getSampleLabel(), 30); | ||
String url = result.getUrlAsString(); | ||
Integer bytes = result.getBytes(); | ||
Long time = result.getTime(); | ||
Long latency = result.getLatency(); | ||
Long starttime = result.getStartTime(); | ||
String status = result.getResponseCode(); | ||
|
||
headerToString() { | ||
String str = "status | thread | "; | ||
str += StringUtils.rightPad("user", 10) + " | "; | ||
str += StringUtils.rightPad("name", 30) + " | db-r | db-w | "; | ||
str += StringUtils.rightPad("dbquerytime", 8) + " | "; | ||
str += StringUtils.rightPad("memory", 8) + " | "; | ||
str += StringUtils.rightPad("files", 6) + " | "; | ||
str += StringUtils.rightPad("load", 6) + " |"; | ||
return str; | ||
} | ||
|
||
toString() { | ||
String str = StringUtils.rightPad(status, 6) + " | "; | ||
str += StringUtils.rightPad(Integer.toString(thread), 6) + " | "; | ||
str += StringUtils.rightPad(username, 10) + " | "; | ||
str += StringUtils.rightPad(name, 30) + " | "; | ||
str += StringUtils.rightPad(dbreads, 4) + " | "; | ||
str += StringUtils.rightPad(Integer.toString(dbwrites), 4) + " | "; | ||
str += StringUtils.rightPad(dbquerytime, 8) + " | "; | ||
str += StringUtils.rightPad(memoryused, 8) + " | "; | ||
str += StringUtils.rightPad(filesincluded, 6) + " | "; | ||
str += StringUtils.rightPad(serverload, 6) + " | "; | ||
str += url; | ||
return str; | ||
} | ||
|
||
toPHP() { | ||
|
||
int bytesPos = sessionsize.indexOf(" bytes"); | ||
int kbsPos = sessionsize.indexOf("KB"); | ||
// Convert the size to KB and strip out the measure. | ||
if (bytesPos != -1) { | ||
sessionsize = "0." + sessionsize.substring(0, bytesPos); | ||
} else if (kbsPos != -1) { | ||
sessionsize = sessionsize.substring(0, kbsPos); | ||
} | ||
|
||
String php = "$results["+thread+"][] = array(\n"; | ||
php += " 'thread'=>"+thread+",\n"; // Int | ||
php += " 'starttime'=>"+starttime+",\n"; // Long | ||
php += " 'dbreads'=>"+Integer.parseInt(dbreads)+",\n"; // String => Int | ||
php += " 'dbwrites'=>"+dbwrites+",\n"; | ||
php += " 'dbquerytime'=>"+dbquerytime+",\n"; | ||
php += " 'memoryused'=>'"+memoryused+"',\n"; | ||
php += " 'filesincluded'=>'"+filesincluded+"',\n"; | ||
php += " 'serverload'=>'"+serverload+"',\n"; | ||
php += " 'sessionsize'=>'"+sessionsize+"',\n"; | ||
php += " 'timeused'=>'"+timeused+"',\n"; | ||
php += " 'name'=>'"+name+"',\n"; | ||
php += " 'url'=>'"+url+"',\n"; | ||
php += " 'bytes'=>'"+bytes+"',\n"; | ||
php += " 'time'=>'"+time+"',\n"; | ||
php += " 'latency'=>'"+latency+"',\n"; | ||
php += ");\n"; | ||
return php; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
EscapeQuotes(String text) { | ||
return text.replace("'", "\\'"); | ||
} | ||
|
||
Runnable mr = MoodleResult(ctx); | ||
|
||
// Get the file (it is created in testStarted). | ||
String filenamepath = "runs/tmpfilename.php"; | ||
|
||
// We add the run info when starting the first thread | ||
if (JMeterUtils.getProperty("headerprinted") == null) { | ||
|
||
// Output headers. | ||
JMeterUtils.setProperty("headerprinted", "1"); | ||
print(mr.headerToString()); | ||
|
||
FileWriter fstream = new FileWriter(filenamepath, true); | ||
BufferedWriter out = new BufferedWriter(fstream); | ||
out.write("$host = '"+vars.get("host")+"';\n"); | ||
out.write("$sitepath = '"+vars.get("sitepath")+"';\n"); | ||
out.write("$group = '"+EscapeQuotes(props.get("group"))+"';\n"); | ||
out.write("$rundesc = '"+EscapeQuotes(props.get("desc"))+"';\n"); | ||
out.write("$users = '"+vars.get("users")+"';\n"); | ||
out.write("$loopcount = '"+vars.get("loops")+"';\n"); | ||
out.write("$rampup = '"+vars.get("rampup")+"';\n"); | ||
out.write("$throughput = '"+vars.get("throughput")+"';\n"); | ||
out.write("$size = '"+vars.get("size")+"';\n"); | ||
out.write("$baseversion = '"+vars.get("moodleversion")+"';\n"); | ||
out.write("$siteversion = '"+EscapeQuotes(props.get("siteversion"))+"';\n"); | ||
out.write("$sitebranch = '"+EscapeQuotes(props.get("sitebranch"))+"';\n"); | ||
out.write("$sitecommit = '"+EscapeQuotes(props.get("sitecommit"))+"';\n"); | ||
out.close(); | ||
|
||
// Send the run timestamp to set it as run filename. | ||
props.put("filepath", "runs/" + vars.get("runtimestamp") + ".php"); | ||
} | ||
|
||
FileWriter fstream = new FileWriter(filenamepath, true); | ||
BufferedWriter out = new BufferedWriter(fstream); | ||
out.write(mr.toPHP()); | ||
out.close(); | ||
|
||
print(mr.toString()); |
20 changes: 20 additions & 0 deletions
20
runner/main/modules/docker-jmeter/libraries/recorderfunctions.bsf
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.io.*; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.jmeter.util.JMeterUtils; // http://jakarta.apache.org/jmeter/api/org/apache/jmeter/util/JMeterUtils.html | ||
|
||
|
||
testStarted(){ | ||
String filenamepath = "runs/tmpfilename.php"; | ||
FileWriter fstream = new FileWriter(filenamepath, true); | ||
BufferedWriter out = new BufferedWriter(fstream); | ||
out.write("<?php\n"); | ||
out.close(); | ||
} | ||
|
||
testEnded(){ | ||
File from = new File("runs/tmpfilename.php"); | ||
File to = new File(JMeterUtils.getProperty("filepath")); | ||
from.renameTo(to); | ||
to.setReadable(true, false); | ||
to.setWritable(true, false); | ||
} |
Oops, something went wrong.