diff --git a/.travis.yml b/.travis.yml index bb221fc..4c46251 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ +addons: + hosts: + - myshorthost + hostname: myshorthost language: java jdk: - - openjdk6 + - openjdk7 install: "mvn clean -B" diff --git a/pom.xml b/pom.xml index 87f68b7..e9a210b 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ kg.apc jmeter-plugins-emulators - 0.3 + 0.4 test diff --git a/src/kg/apc/perfmon/AgentTool.java b/src/kg/apc/perfmon/AgentTool.java index ef8e7ff..4d182d2 100644 --- a/src/kg/apc/perfmon/AgentTool.java +++ b/src/kg/apc/perfmon/AgentTool.java @@ -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); } diff --git a/src/kg/apc/perfmon/PerfMonMetricGetter.java b/src/kg/apc/perfmon/PerfMonMetricGetter.java index 90da6f2..e1a2dfa 100644 --- a/src/kg/apc/perfmon/PerfMonMetricGetter.java +++ b/src/kg/apc/perfmon/PerfMonMetricGetter.java @@ -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()); } } } diff --git a/src/kg/apc/perfmon/PerfMonWorker.java b/src/kg/apc/perfmon/PerfMonWorker.java index 3d60fbf..04bebcd 100644 --- a/src/kg/apc/perfmon/PerfMonWorker.java +++ b/src/kg/apc/perfmon/PerfMonWorker.java @@ -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(); @@ -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; + } } diff --git a/src/kg/apc/perfmon/metrics/AbstractPerfMonMetric.java b/src/kg/apc/perfmon/metrics/AbstractPerfMonMetric.java index 7aab3ae..b9131ee 100644 --- a/src/kg/apc/perfmon/metrics/AbstractPerfMonMetric.java +++ b/src/kg/apc/perfmon/metrics/AbstractPerfMonMetric.java @@ -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) { @@ -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); diff --git a/src/kg/apc/perfmon/metrics/PerfMonMetricsCreator.java b/src/kg/apc/perfmon/metrics/PerfMonMetricsCreator.java index 1dd732c..e9a6a34 100644 --- a/src/kg/apc/perfmon/metrics/PerfMonMetricsCreator.java +++ b/src/kg/apc/perfmon/metrics/PerfMonMetricsCreator.java @@ -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); } diff --git a/src/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImpl.java b/src/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImpl.java index 35bd7c9..c08ae7a 100644 --- a/src/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImpl.java +++ b/src/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImpl.java @@ -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); diff --git a/src/kg/apc/perfmon/metrics/PerfMonMetricsService.java b/src/kg/apc/perfmon/metrics/PerfMonMetricsService.java index 5e75ec6..4ee8be2 100644 --- a/src/kg/apc/perfmon/metrics/PerfMonMetricsService.java +++ b/src/kg/apc/perfmon/metrics/PerfMonMetricsService.java @@ -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()); diff --git a/test/kg/apc/perfmon/metrics/AbstractPerfMonMetricTest.java b/test/kg/apc/perfmon/metrics/AbstractPerfMonMetricTest.java index 94283ef..16037be 100644 --- a/test/kg/apc/perfmon/metrics/AbstractPerfMonMetricTest.java +++ b/test/kg/apc/perfmon/metrics/AbstractPerfMonMetricTest.java @@ -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()); } diff --git a/test/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImplTest.java b/test/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImplTest.java index 155614a..c53eebc 100644 --- a/test/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImplTest.java +++ b/test/kg/apc/perfmon/metrics/PerfMonMetricsCreatorImplTest.java @@ -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()); } @@ -40,7 +40,7 @@ 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; } @@ -48,4 +48,17 @@ public final void testGetMetricProviderError() { 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()); + } + + } diff --git a/test/kg/apc/perfmon/metrics/PerfMonMetricsServiceTest.java b/test/kg/apc/perfmon/metrics/PerfMonMetricsServiceTest.java index 0769128..f9f962f 100644 --- a/test/kg/apc/perfmon/metrics/PerfMonMetricsServiceTest.java +++ b/test/kg/apc/perfmon/metrics/PerfMonMetricsServiceTest.java @@ -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()); diff --git a/test/kg/apc/perfmon/metrics/jmx/JMXConnectorHelperTest.java b/test/kg/apc/perfmon/metrics/jmx/JMXConnectorHelperTest.java index 074a9d2..f6a3de1 100644 --- a/test/kg/apc/perfmon/metrics/jmx/JMXConnectorHelperTest.java +++ b/test/kg/apc/perfmon/metrics/jmx/JMXConnectorHelperTest.java @@ -9,7 +9,7 @@ /** * @author undera */ -public class JMXConnectorHelperTest extends TestCase { +public class JMXConnectorHelperTest extends TestCase { public JMXConnectorHelperTest(String testName) { super(testName);