Skip to content

Commit

Permalink
Merge pull request #4 from artem-fedorov/no-exec-flag
Browse files Browse the repository at this point in the history
No exec flag
  • Loading branch information
undera authored Aug 8, 2017
2 parents 4bda438 + 79b8e21 commit 08bf55f
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
addons:
hosts:
- myshorthost
hostname: myshorthost
language: java
jdk:
- openjdk6
- openjdk7
install: "mvn clean -B"

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-emulators</artifactId>
<version>0.3</version>
<version>0.4</version>
<scope>test</scope>
</dependency>

Expand Down
3 changes: 3 additions & 0 deletions src/kg/apc/perfmon/AgentTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ protected int processParams(ListIterator args) throws UnsupportedOperationExcept
} else if (nextArg.equals("--agent-version")) {
args.remove();
worker.logVersion();
} else if (nextArg.equalsIgnoreCase("--no-exec")) {
args.remove();
worker.setNoExec(true);
} else {
throw new UnsupportedOperationException("Unrecognized option: " + nextArg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/kg/apc/perfmon/PerfMonMetricGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ private void setUpMetrics(String[] params) throws IOException {
for (int n = 0; n < params.length; n++) {
String metricParams = "";
String metricType = params[n];
if (DVOETOCHIE.contains(metricType)) {
if (metricType.contains(DVOETOCHIE)) {
metricParams = metricType.substring(metricType.indexOf(DVOETOCHIE) + 1).trim();
metricType = metricType.substring(0, metricType.indexOf(DVOETOCHIE)).trim();
}

metrics[n] = AbstractPerfMonMetric.createMetric(metricType, metricParams, sigarProxy);
metrics[n] = AbstractPerfMonMetric.createMetric(metricType, metricParams, sigarProxy, controller.isNoExec());
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/kg/apc/perfmon/PerfMonWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class PerfMonWorker implements Runnable {
private final SigarProxy sigar;
private long numConnections = 0;
private boolean autoShutdown = false;
private boolean isNoExec = false;

public PerfMonWorker() throws IOException {
acceptSelector = Selector.open();
Expand Down Expand Up @@ -369,4 +370,12 @@ protected void connectUDPClient(SocketAddress remoteAddr, DatagramChannel channe
udpConnections.put(remoteAddr, getter);
}
}

public boolean isNoExec() {
return isNoExec;
}

public void setNoExec(boolean noExec) {
isNoExec = noExec;
}
}
4 changes: 2 additions & 2 deletions src/kg/apc/perfmon/metrics/AbstractPerfMonMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected int getUnitDividingFactor(String unit) {

abstract public void getValue(StringBuffer res) throws Exception;

public static AbstractPerfMonMetric createMetric(String metricType, String metricParamsStr, SigarProxy sigarProxy) {
public static AbstractPerfMonMetric createMetric(String metricType, String metricParamsStr, SigarProxy sigarProxy, boolean isNoExec) {
log.debug("Creating metric: " + metricType + " with params: " + metricParamsStr);
AbstractPerfMonMetric metric;
if (metricType.indexOf(' ') > 0) {
Expand All @@ -45,7 +45,7 @@ public static AbstractPerfMonMetric createMetric(String metricType, String metri
PerfMonMetricsService service = PerfMonMetricsService.getInstance();

try {
metric = service.getMetric(metricType, metricParams, sigarProxy);
metric = service.getMetric(metricType, metricParams, sigarProxy, isNoExec);
} catch (IllegalArgumentException ex) {
log.debug(ex.toString());
log.debug("Invalid parameters specified for metric " + metricType + ": " + metricParams);
Expand Down
2 changes: 1 addition & 1 deletion src/kg/apc/perfmon/metrics/PerfMonMetricsCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface PerfMonMetricsCreator {

public AbstractPerfMonMetric getMetricProvider(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy);
public AbstractPerfMonMetric getMetricProvider(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy, boolean isNoExec);

}
7 changes: 5 additions & 2 deletions src/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ public class PerfMonMetricsCreatorImpl implements PerfMonMetricsCreator {

private static final Logger log = LoggingManager.getLoggerForClass();

public AbstractPerfMonMetric getMetricProvider(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy) {
public AbstractPerfMonMetric getMetricProvider(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy, boolean isNoExec) {
AbstractPerfMonMetric metric;
if (metricType.equalsIgnoreCase("exec")) {
if (isNoExec && (metricType.equalsIgnoreCase("exec") || metricType.equalsIgnoreCase("tail"))) {
log.warn("Agent started in safe mode, 'exec' and 'tail' metrics are not available");
metric = new InvalidPerfMonMetric();
} else if (metricType.equalsIgnoreCase("exec")) {
metric = new ExecMetric(metricParams);
} else if (metricType.equalsIgnoreCase("tail")) {
metric = new TailMetric(metricParams);
Expand Down
4 changes: 2 additions & 2 deletions src/kg/apc/perfmon/metrics/PerfMonMetricsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public static synchronized PerfMonMetricsService getInstance() {
return service;
}

public AbstractPerfMonMetric getMetric(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy) throws IllegalArgumentException, RuntimeException {
public AbstractPerfMonMetric getMetric(String metricType, MetricParamsSigar metricParams, SigarProxy sigarProxy, boolean isNoExec) throws IllegalArgumentException, RuntimeException {
AbstractPerfMonMetric metric = null;

Iterator mCreators = loader.iterator();
while (metric == null && mCreators.hasNext()) {
PerfMonMetricsCreator mCreator = (PerfMonMetricsCreator) mCreators.next();
try {
metric = mCreator.getMetricProvider(metricType, metricParams, sigarProxy);
metric = mCreator.getMetricProvider(metricType, metricParams, sigarProxy, isNoExec);
} catch (Exception e) {
log.debug("Error when getting metrics from: " + mCreator.getClass());
log.debug(e.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion test/kg/apc/perfmon/metrics/AbstractPerfMonMetricTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testCreateMetric() {
String metricParams = "idle";
SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
Class expResult = CPUTotalMetric.class;
AbstractPerfMonMetric result = AbstractPerfMonMetric.createMetric(metricType, metricParams, sigarProxy);
AbstractPerfMonMetric result = AbstractPerfMonMetric.createMetric(metricType, metricParams, sigarProxy, false);
assertNotNull(result);
assertEquals(expResult, result.getClass());
}
Expand Down
17 changes: 15 additions & 2 deletions test/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final void testGetMetricProvider() {
SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
MetricParamsSigar metricParamsSigar = MetricParamsSigar.createFromString(metricParams, sigarProxy);
Class expResult = CPUTotalMetric.class;
AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy);
AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy, false);
assertEquals(expResult, result.getClass());
}

Expand All @@ -40,12 +40,25 @@ public final void testGetMetricProviderError() {
SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
MetricParamsSigar metricParamsSigar = MetricParamsSigar.createFromString(metricParams, sigarProxy);
try {
AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy);
AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy, false);
} catch (Throwable e) {
catched = e;
}
assertNotNull(catched);
assertEquals(RuntimeException.class, catched.getClass());
}

public final void testNoExec() {
PerfMonMetricsCreatorImpl getter = new PerfMonMetricsCreatorImpl();
System.out.println("no-exec");
String metricType = "exec";
String metricParams = "";
SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
MetricParamsSigar metricParamsSigar = MetricParamsSigar.createFromString(metricParams, sigarProxy);
AbstractPerfMonMetric result = getter.getMetricProvider(metricType, metricParamsSigar, sigarProxy, true);
assertNotNull(result);
assertEquals(InvalidPerfMonMetric.class, result.getClass());
}


}
2 changes: 1 addition & 1 deletion test/kg/apc/perfmon/metrics/PerfMonMetricsServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final void testGetMetric() {
SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
MetricParamsSigar metricParams = MetricParamsSigar.createFromString("idle", sigarProxy);

AbstractPerfMonMetric metric = service.getMetric(metricType, metricParams, sigarProxy);
AbstractPerfMonMetric metric = service.getMetric(metricType, metricParams, sigarProxy, false);

assertNotNull(metric);
assertEquals(CPUTotalMetric.class, metric.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @author undera
*/
public class JMXConnectorHelperTest extends TestCase {
public class JMXConnectorHelperTest extends TestCase {

public JMXConnectorHelperTest(String testName) {
super(testName);
Expand Down

0 comments on commit 08bf55f

Please sign in to comment.