Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some missing classes from last commit
- Loading branch information
Showing
5 changed files
with
196 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ classes/ | |
output/ | ||
temp/ | ||
|
||
!/src/org/yawlfoundation/yawl/balancer/output/ |
120 changes: 120 additions & 0 deletions
120
src/org/yawlfoundation/yawl/balancer/output/AbstractLoadOutputter.java
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,120 @@ | ||
package org.yawlfoundation.yawl.balancer.output; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Michael Adams | ||
* @date 21/8/17 | ||
*/ | ||
abstract class AbstractLoadOutputter { | ||
|
||
protected FileWriter _out; | ||
|
||
|
||
public AbstractLoadOutputter(String baseFileName, String engineName) { | ||
try { | ||
_out = openFile(baseFileName, engineName); | ||
writeHeader(); | ||
} | ||
catch (IOException ioe) { | ||
if (_out != null) _out = null; | ||
} | ||
} | ||
|
||
|
||
abstract void writeValues(Map<String, String> values) throws IOException; | ||
|
||
abstract String getHeader(); | ||
|
||
|
||
public void closeFile() { | ||
if (_out != null) { | ||
try { | ||
_out.flush(); | ||
_out.close(); | ||
} | ||
catch (IOException ioe) { | ||
// we tried | ||
} | ||
} | ||
} | ||
|
||
|
||
public void add(String line) { | ||
if (_out != null) { | ||
try { | ||
for (String sub : line.split("\\r?\\n")) { | ||
writeTime(); | ||
_out.write(sub); | ||
_out.write('\n'); | ||
} | ||
_out.flush(); | ||
} | ||
catch (IOException ioe) { | ||
// forget it | ||
} | ||
} | ||
} | ||
|
||
|
||
public void add(Map<String, String> values) { | ||
if (_out != null) { | ||
try { | ||
writeTime(); | ||
writeValues(values); | ||
_out.write('\n'); | ||
_out.flush(); | ||
} | ||
catch (IOException ioe) { | ||
// forget it | ||
} | ||
} | ||
} | ||
|
||
|
||
private void writeHeader() throws IOException { | ||
if (_out != null) { | ||
_out.write(getHeader()); | ||
_out.write('\n'); | ||
} | ||
} | ||
|
||
|
||
private void writeTime() throws IOException { | ||
if (_out != null) { | ||
Date date = new Date(); | ||
String fDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") | ||
.format(new Date()); | ||
_out.write(fDate); | ||
_out.write("," + date.getTime() + ","); | ||
} | ||
} | ||
|
||
|
||
private FileWriter openFile(String baseFileName, String engineName) throws IOException { | ||
File f = getFile(baseFileName, engineName); | ||
if (f.createNewFile()) { | ||
return new FileWriter(f); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
private File getFile(String baseFileName, String engineName) { | ||
String root = System.getenv("CATALINA_HOME"); | ||
String baseName = root + "/logs/" + baseFileName + '_' + engineName; | ||
String extn = ".log"; | ||
File f = new File(baseName + extn); | ||
int i = 1; | ||
while (f.exists()) { | ||
f = new File(baseName + "_" + i++ + extn); | ||
} | ||
return f; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/org/yawlfoundation/yawl/balancer/output/BusynessOutputter.java
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,45 @@ | ||
package org.yawlfoundation.yawl.balancer.output; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Michael Adams | ||
* @date 21/8/17 | ||
*/ | ||
public class BusynessOutputter extends AbstractLoadOutputter { | ||
|
||
|
||
public BusynessOutputter(String engineName) { | ||
super("busyness", engineName); | ||
} | ||
|
||
|
||
protected void writeValues(Map<String, String> values) throws IOException { | ||
_out.write(values.get("cpu_process")); | ||
_out.write(','); | ||
_out.write(values.get("cpu_system")); | ||
_out.write(','); | ||
_out.write(values.get("thread_count")); | ||
_out.write(','); | ||
_out.write(values.get("threads_busy")); | ||
_out.write(','); | ||
_out.write(values.get("threads_free")); | ||
_out.write(','); | ||
_out.write(values.get("process_time_factor")); | ||
_out.write(','); | ||
_out.write(values.get("requests_factor")); | ||
_out.write(','); | ||
_out.write(values.get("threads_factor")); | ||
_out.write(','); | ||
_out.write(values.get("busyness")); | ||
} | ||
|
||
|
||
protected String getHeader() { | ||
return "time,timestamp,cpu_process,cpu_system,thread_count," + | ||
"threads_busy,threads_free,process_time_factor,requests_factor," + | ||
"threads_factor,busyness"; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/org/yawlfoundation/yawl/balancer/output/RequestStatOutputter.java
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,29 @@ | ||
package org.yawlfoundation.yawl.balancer.output; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Michael Adams | ||
* @date 21/8/17 | ||
*/ | ||
public class RequestStatOutputter extends AbstractLoadOutputter { | ||
|
||
|
||
public RequestStatOutputter(String engineName) { | ||
super("requests", engineName); | ||
} | ||
|
||
|
||
protected void writeValues(Map<String, String> values) throws IOException { } | ||
|
||
|
||
protected String getHeader() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("time,timestamp,name,min,max,mean,count,perSec,"); | ||
sb.append("prevMin,prevMax,prevMean,prevCount,prevPerSec,"); | ||
sb.append("allMin,allMax,allMean,allCount,allPerSec"); | ||
return sb.toString(); | ||
} | ||
|
||
} |
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