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() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// Compute for the actual duration window of the sampler
|
|
||||||
long endTime = System.currentTimeMillis() + duration - rampDownTime;
|
|
||||||
|
|
||||||
onRampUpStart();
|
onRampUpStart();
|
||||||
if (perfEventListener != null) {
|
if (perfEventListener != null) {
|
||||||
perfEventListener.onRampUpStart(this);
|
perfEventListener.onRampUpStart(this);
|
||||||
|
@ -91,15 +88,7 @@ public abstract class AbstractPerformanceSampler extends AbstractObjectPropertie
|
||||||
perfEventListener.onSamplerStart(this);
|
perfEventListener.onSamplerStart(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (System.currentTimeMillis() < endTime) {
|
sample();
|
||||||
try {
|
|
||||||
Thread.sleep(interval);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
sampleData();
|
|
||||||
sampleIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
onSamplerEnd();
|
onSamplerEnd();
|
||||||
if (perfEventListener != null) {
|
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 abstract void sampleData();
|
||||||
|
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
|
|
|
@ -16,11 +16,11 @@ public class CpuSamplerTask extends AbstractPerformanceSampler {
|
||||||
|
|
||||||
public void createPlugin(String osName) throws IOException {
|
public void createPlugin(String osName) throws IOException {
|
||||||
if (osName == null) {
|
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)) {
|
if (osName.equalsIgnoreCase(CpuSamplerPlugin.LINUX)) {
|
||||||
plugin = new LinuxCpuSamplerPlugin();
|
plugin = new LinuxCpuSamplerPlugin(getInterval());
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("No CPU Sampler Plugin found for OS: " + osName + ". CPU Sampler will not be started.");
|
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());
|
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 final Object mutex = new Object();
|
||||||
private List clients = new ArrayList();
|
private List clients = new ArrayList();
|
||||||
|
|
||||||
|
public void registerClient(MeasurableClient client) {
|
||||||
|
synchronized (mutex) {
|
||||||
|
clients.add(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void sampleData() {
|
public void sampleData() {
|
||||||
for (Iterator i = clients.iterator(); i.hasNext();) {
|
for (Iterator i = clients.iterator(); i.hasNext();) {
|
||||||
MeasurableClient client = (MeasurableClient) i.next();
|
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() {
|
protected void onSamplerStart() {
|
||||||
// Reset the throughput of the clients
|
// Reset the throughput of the clients
|
||||||
for (Iterator i = clients.iterator(); i.hasNext();) {
|
for (Iterator i = clients.iterator(); i.hasNext();) {
|
||||||
|
|
|
@ -16,4 +16,6 @@ public interface CpuSamplerPlugin {
|
||||||
public final static String OS_2 = "OS/2";
|
public final static String OS_2 = "OS/2";
|
||||||
|
|
||||||
public String getCpuUtilizationStats();
|
public String getCpuUtilizationStats();
|
||||||
|
public void start();
|
||||||
|
public void stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,75 @@
|
||||||
package org.apache.activemq.tool.sampler.plugins;
|
package org.apache.activemq.tool.sampler.plugins;
|
||||||
|
|
||||||
|
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.StringTokenizer;
|
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 {
|
try {
|
||||||
Process p = Runtime.getRuntime().exec(vmstat);
|
vmstatProcess.waitFor();
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
|
} 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
|
br.readLine(); // throw away the first line
|
||||||
|
|
||||||
String header = br.readLine();
|
String header = br.readLine();
|
||||||
String data = br.readLine();
|
String data;
|
||||||
|
|
||||||
br.close();
|
while (!stop.get()) {
|
||||||
|
data = br.readLine();
|
||||||
// Convert to CSV of key=value pair
|
if (data != null) {
|
||||||
return convertToCSV(header, data);
|
String csvData = convertToCSV(header, data);
|
||||||
} catch (Exception e) {
|
synchronized (mutex) {
|
||||||
e.printStackTrace();
|
result = csvData;
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
vmstatProcess.destroy();
|
||||||
|
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCpuUtilizationStats() {
|
||||||
|
String data;
|
||||||
|
synchronized (mutex) {
|
||||||
|
data = result;
|
||||||
|
result = "";
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public String getVmstat() {
|
public String getVmstat() {
|
||||||
return vmstat;
|
return vmstat;
|
||||||
|
|
Loading…
Reference in New Issue