mirror of https://github.com/apache/activemq.git
Modify the vmstat plugin as it was returning only the summary previously.
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@417341 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a6f93512b4
commit
cc1986ff12
|
@ -72,9 +72,6 @@ public abstract class AbstractPerformanceSampler extends AbstractObjectPropertie
|
|||
|
||||
public void run() {
|
||||
try {
|
||||
// Compute for the actual duration window of the sampler
|
||||
long endTime = System.currentTimeMillis() + duration - rampDownTime;
|
||||
|
||||
onRampUpStart();
|
||||
if (perfEventListener != null) {
|
||||
perfEventListener.onRampUpStart(this);
|
||||
|
@ -91,15 +88,7 @@ public abstract class AbstractPerformanceSampler extends AbstractObjectPropertie
|
|||
perfEventListener.onSamplerStart(this);
|
||||
}
|
||||
|
||||
while (System.currentTimeMillis() < endTime) {
|
||||
try {
|
||||
Thread.sleep(interval);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sampleData();
|
||||
sampleIndex++;
|
||||
}
|
||||
sample();
|
||||
|
||||
onSamplerEnd();
|
||||
if (perfEventListener != null) {
|
||||
|
@ -124,6 +113,21 @@ public abstract class AbstractPerformanceSampler extends AbstractObjectPropertie
|
|||
}
|
||||
}
|
||||
|
||||
protected void sample() {
|
||||
// Compute for the actual duration window of the sampler
|
||||
long endTime = System.currentTimeMillis() + duration - rampDownTime - rampUpTime;
|
||||
|
||||
while (System.currentTimeMillis() < endTime) {
|
||||
try {
|
||||
Thread.sleep(interval);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sampleData();
|
||||
sampleIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void sampleData();
|
||||
|
||||
public boolean isRunning() {
|
||||
|
|
|
@ -16,11 +16,11 @@ public class CpuSamplerTask extends AbstractPerformanceSampler {
|
|||
|
||||
public void createPlugin(String osName) throws IOException {
|
||||
if (osName == null) {
|
||||
throw new IOException("No defined OS name found. Foound: " + osName);
|
||||
throw new IOException("No defined OS name found. Found: " + osName);
|
||||
}
|
||||
|
||||
if (osName.equalsIgnoreCase(CpuSamplerPlugin.LINUX)) {
|
||||
plugin = new LinuxCpuSamplerPlugin();
|
||||
plugin = new LinuxCpuSamplerPlugin(getInterval());
|
||||
} else {
|
||||
throw new IOException("No CPU Sampler Plugin found for OS: " + osName + ". CPU Sampler will not be started.");
|
||||
}
|
||||
|
@ -31,4 +31,18 @@ public class CpuSamplerTask extends AbstractPerformanceSampler {
|
|||
perfReportWriter.writeCsvData(ReportPlugin.REPORT_PLUGIN_CPU, plugin.getCpuUtilizationStats());
|
||||
}
|
||||
}
|
||||
|
||||
protected void onRampUpStart() {
|
||||
super.onRampUpStart();
|
||||
if (plugin != null) {
|
||||
plugin.start();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onRampDownEnd() {
|
||||
super.onRampDownEnd();
|
||||
if (plugin != null) {
|
||||
plugin.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,12 @@ public class ThroughputSamplerTask extends AbstractPerformanceSampler {
|
|||
private final Object mutex = new Object();
|
||||
private List clients = new ArrayList();
|
||||
|
||||
public void registerClient(MeasurableClient client) {
|
||||
synchronized (mutex) {
|
||||
clients.add(client);
|
||||
}
|
||||
}
|
||||
|
||||
public void sampleData() {
|
||||
for (Iterator i = clients.iterator(); i.hasNext();) {
|
||||
MeasurableClient client = (MeasurableClient) i.next();
|
||||
|
@ -23,12 +29,6 @@ public class ThroughputSamplerTask extends AbstractPerformanceSampler {
|
|||
}
|
||||
}
|
||||
|
||||
public void registerClient(MeasurableClient client) {
|
||||
synchronized (mutex) {
|
||||
clients.add(client);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSamplerStart() {
|
||||
// Reset the throughput of the clients
|
||||
for (Iterator i = clients.iterator(); i.hasNext();) {
|
||||
|
|
|
@ -16,4 +16,6 @@ public interface CpuSamplerPlugin {
|
|||
public final static String OS_2 = "OS/2";
|
||||
|
||||
public String getCpuUtilizationStats();
|
||||
public void start();
|
||||
public void stop();
|
||||
}
|
||||
|
|
|
@ -1,32 +1,75 @@
|
|||
package org.apache.activemq.tool.sampler.plugins;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class LinuxCpuSamplerPlugin implements CpuSamplerPlugin {
|
||||
public class LinuxCpuSamplerPlugin implements CpuSamplerPlugin, Runnable {
|
||||
|
||||
private String vmstat = "vmstat";
|
||||
private Process vmstatProcess;
|
||||
private String vmstat;
|
||||
private String result = "";
|
||||
private final Object mutex = new Object();
|
||||
private AtomicBoolean stop = new AtomicBoolean(false);
|
||||
|
||||
public String getCpuUtilizationStats() {
|
||||
public LinuxCpuSamplerPlugin(long intervalInMs) {
|
||||
vmstat = "vmstat -n " + (int)(intervalInMs / 1000);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
stop.set(false);
|
||||
Thread t = new Thread(this);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
stop.set(true);
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(vmstat);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
|
||||
vmstatProcess.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
vmstatProcess = Runtime.getRuntime().exec(vmstat);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(vmstatProcess.getInputStream()), 1024);
|
||||
|
||||
br.readLine(); // throw away the first line
|
||||
|
||||
String header = br.readLine();
|
||||
String data = br.readLine();
|
||||
String data;
|
||||
|
||||
br.close();
|
||||
|
||||
// Convert to CSV of key=value pair
|
||||
return convertToCSV(header, data);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
while (!stop.get()) {
|
||||
data = br.readLine();
|
||||
if (data != null) {
|
||||
String csvData = convertToCSV(header, data);
|
||||
synchronized (mutex) {
|
||||
result = csvData;
|
||||
}
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
vmstatProcess.destroy();
|
||||
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getCpuUtilizationStats() {
|
||||
String data;
|
||||
synchronized (mutex) {
|
||||
data = result;
|
||||
result = "";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getVmstat() {
|
||||
return vmstat;
|
||||
|
|
Loading…
Reference in New Issue