/** * Perform one measurement with potential multiple records. * * @param monitoringController * The monitoring controller for this probe. * * @throws Exception * depending on the concrete sampler different exceptions can be raised */ @Override public final void sample(final IMonitoringController monitoringController) throws Exception { if (!monitoringController.isMonitoringEnabled()) { return; } final long timestamp = monitoringController.getTimeSource().getTime(); final String hostname = monitoringController.getHostname(); final IMonitoringRecord[] records = this.createNewMonitoringRecords(timestamp, hostname, VM_NAME, monitoringController); for (final IMonitoringRecord record : records) { monitoringController.newMonitoringRecord(record); } }
@Override protected void onTerminating() { this.monitoringController.terminateMonitoring(); try { this.monitoringController.waitForTermination(WAIT_TIMEOUT_IN_MS); } catch (final InterruptedException e) { throw new IllegalStateException(e); } finally { super.onTerminating(); } } }
@Override public void onStarting() { final IMonitoringController monitoringController = MonitoringController.getInstance(); try { final HostApplicationMetaData record = new HostApplicationMetaData("Default System", InetAddress.getLocalHost().getHostAddress(), monitoringController.getHostname(), monitoringController.getName()); this.writeMonitoringRecord(record); } catch (final UnknownHostException e) { LOGGER.warn("An exception occurred", e); } }
/** * Creates a new instance of this class, using the given instance of a {@link MonitoringController} as controller. * * @param monitoringCtrl * The controller of this interceptor. */ public OperationExecutionSOAPResponseInInterceptor(final IMonitoringController monitoringCtrl) { this.monitoringController = monitoringCtrl; this.timeSource = this.monitoringController.getTimeSource(); this.vmName = this.monitoringController.getHostname(); }
@AfterReturning(marker = BodyMarker.class, scope = "") public static void onMethodExit(final MethodStaticContext msc) { if (!CTRLINST.isMonitoringEnabled() || !CTRLINST.isProbeActivated(signature)) { return; } if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } // measure after successful execution CTRLINST.newMonitoringRecord(new AfterOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), signature, clazz)); }
public static final void monitorBranch(final int branchID, final int branchingOutcome) { if (!CTRLINST.isMonitoringEnabled()) { return; } // try-catch in order to avoid that any exception is propagated to the application code. try { CTRLINST.newMonitoringRecord(new BranchingRecord(TIMESOURCE.getTime(), branchID, branchingOutcome)); } catch (final Exception ex) { // NOPMD NOCS (Exceptions) LOGGER.error("Error monitoring branching", ex); } } }
/** * Test if probe activation/deactivation works properly and is not affected by enabling and disabling monitoring. * Starting with disabled adaptive monitoring. */ @Test public void testEnabledDisabledMatchingWithoutAdaptiveMonitoring() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "false"); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); ctrl.deactivateProbe("*"); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.disableMonitoring(); Assert.assertFalse(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.enableMonitoring(); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.terminateMonitoring(); }
@Test public void testSingleRecord() throws IOException, InterruptedException { final String testId = "testSingleRecord"; final int recordCount = 1; final int taskRunInterval = 10; final int deferredWriteDelay = 50; final IMonitoringController controller = this.createController(testId, taskRunInterval, deferredWriteDelay); for (int recordIndex = 0; recordIndex < recordCount; recordIndex++) { final OperationExecutionRecord record = new OperationExecutionRecord("op()", "SESS-ID", 0, recordIndex, recordIndex, "host", recordIndex, 1); controller.newMonitoringRecord(record); } // Terminate monitoring and wait for termination controller.terminateMonitoring(); controller.waitForTermination(2000); // Retrieve written data from the data storage final byte[] data = TestRawDataStorage.getInstance().getData(testId); // Check some basic numbers, since full decoding is not yet supported final ByteBuffer dataBuffer = ByteBuffer.wrap(data); // Read the string table offset (last four bytes), plus 8 bytes for the container header dataBuffer.position(data.length - 4); final int stringTableOffset = dataBuffer.getInt() + 8; // Read the number of strings in the string table dataBuffer.position(stringTableOffset); final int numberOfStrings = VariableLengthEncoding.decodeInt(dataBuffer); // Check the size of the string table Assert.assertEquals(9, numberOfStrings); }
/** * Test if terminating an enabled controller works. */ @Test public void testMonitoringEnabledToTerminated() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); configuration.setProperty(ConfigurationKeys.MONITORING_ENABLED, "true"); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Change to terminated kieker.terminateMonitoring(); // Check values when terminated Assert.assertEquals("Unexpected monitoringEnabled value", false, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", true, kieker.isMonitoringTerminated()); kieker.terminateMonitoring(); }
@Test public void testDeactivationAndReactivation() throws InterruptedException { final long period = 1500; // 1500 ms final long offset = 300; // i.e., 1st event after 300 ms final ISigarSamplerFactory sigarFactory = SigarSamplerFactory.INSTANCE; final MemSwapUsageSampler sampler = sigarFactory.createSensorMemSwapUsage(); this.monitoringController.schedulePeriodicSampler(sampler, offset, period, TimeUnit.MILLISECONDS); Thread.sleep(3600); // sleep 3.6 seconds // Expecting sampling trigger events at milliseconds 300, 1800, 3300 final int numEventsBeforeDisabled = this.recordListFilledByListWriter.size(); final String pattern = SignatureFactory.createMemSwapSignature(); this.monitoringController.deactivateProbe(pattern); Thread.sleep(2000); // sleep 2 seconds while being disabled // There should be no new trigger events final int numEventsWhileDisabled = this.recordListFilledByListWriter.size() - numEventsBeforeDisabled; this.monitoringController.activateProbe(pattern); Thread.sleep(2000); // sleep 2 seconds while being re-enabled // There should be at least one new trigger event final int numEventsAfterReEnabled = this.recordListFilledByListWriter.size() - numEventsBeforeDisabled; final boolean isInstanceOf = this.recordListFilledByListWriter.get(0) instanceof MemSwapUsageRecord; Assert.assertTrue("Unexpected instance of IMonitoringRecord", isInstanceOf); Assert.assertEquals("Unexpected number of triggering events before disabling", 3, numEventsBeforeDisabled); Assert.assertEquals("Unexpected number of triggering events while disabled", 0, numEventsWhileDisabled); Assert.assertTrue("Unexpected at least one triggering events after being re-enabled. Found " + numEventsAfterReEnabled, numEventsAfterReEnabled > 0); // NOCS (MagicNumberCheck) this.monitoringController.terminateMonitoring(); }
@Override protected void checkControllerStateAfterRecordsPassedToController(final IMonitoringController monitoringController) throws Exception { Assert.assertTrue(monitoringController.isMonitoringEnabled()); monitoringController.terminateMonitoring(); this.analysisThread.awaitTermination(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); }
/** * Test if disabling enabled monitoring works. */ @Test public void testMonitoringEnabledToDisabled() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); configuration.setProperty(ConfigurationKeys.MONITORING_ENABLED, "true"); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Check values when enabled Assert.assertEquals("Unexpected monitoringEnabled value", true, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); // Change to disabled Assert.assertTrue("disableMonitoring returned false", kieker.disableMonitoring()); // Check values when disabled Assert.assertEquals("Unexpected monitoringEnabled value", false, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); kieker.terminateMonitoring(); }
/** * Test if enabling monitoring when starting disabled works. */ @Test public void testMonitoringDisabledToEnabled() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); configuration.setProperty(ConfigurationKeys.MONITORING_ENABLED, "false"); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Check values when disabled Assert.assertEquals("Unexpected monitoringEnabled value", false, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); // Change to enabled Assert.assertTrue("enableMonitoring returned false", kieker.enableMonitoring()); // Check values when enabled Assert.assertEquals("Unexpected monitoringEnabled value", true, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); kieker.terminateMonitoring(); }
/** * Test pattern matching algorithm. */ @Test public void testMatching() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_CONFIG_FILE, this.configFile.getAbsolutePath()); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); // generate test signature final String signature = "public void kieker.test.monitoring.junit.core.controller.TestProbeController.testIt()"; // test methods final String pattern = "..* kieker..*.*(..)"; Assert.assertFalse(ctrl.activateProbe("InvalidPatternException expected")); Assert.assertTrue(ctrl.activateProbe(pattern)); Assert.assertTrue(ctrl.isProbeActivated(signature)); Assert.assertTrue(ctrl.deactivateProbe(pattern)); Assert.assertFalse(ctrl.isProbeActivated(signature)); ctrl.terminateMonitoring(); }
/** * Test if activation and deactivation work for sample probes. */ @Test public void testSpecialProbes() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); final String memSwapSignature = SignatureFactory.createMemSwapSignature(); // %MEM_SWAP final String cpuSignature = SignatureFactory.createCPUSignature(); // %CPU Assert.assertTrue(ctrl.isProbeActivated(memSwapSignature)); // default is true ctrl.deactivateProbe(memSwapSignature); // this entry deactivates the MemSwapProbe Assert.assertFalse(ctrl.isProbeActivated(memSwapSignature)); Assert.assertTrue(ctrl.isProbeActivated(cpuSignature)); // default is true ctrl.deactivateProbe(cpuSignature); // this entry deactivates the CpuProbe Assert.assertFalse(ctrl.isProbeActivated(cpuSignature)); // Independent of 'cpuSignature' all specific signatures are active by default. Assert.assertTrue(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(0))); // %CPU::0 ctrl.deactivateProbe(SignatureFactory.createCPUSignature(0)); Assert.assertFalse(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(0))); Assert.assertTrue(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(1))); // %CPU::1 ctrl.deactivateProbe("%CPU::.*"); // regular expressions also allowed, this one deactivates all probes Assert.assertFalse(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(0))); Assert.assertFalse(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(1))); Assert.assertFalse(ctrl.isMonitoringTerminated()); ctrl.terminateMonitoring(); }
final List<String> list = ctrl.getProbePatternList(); Assert.assertTrue(list.isEmpty()); ctrl.activateProbe("void test.Test()"); ctrl.deactivateProbe("Test test.Test.getTest()"); final List<String> list2 = this.readFromConfigFile(); Assert.assertArrayEquals(new String[] { "+void test.Test()", "-Test test.Test.getTest()", }, list2.toArray()); list3.add("+ public void test.Test.getNothing()"); list3.add("+ Test test.Test.getTest()"); ctrl.setProbePatternList(list3); final List<String> list4 = this.readFromConfigFile(); Assert.assertArrayEquals(new String[] { "-public * test.Test.get*()", "+public void test.Test.getNothing()", "+Test test.Test.getTest()", }, list4.toArray()); Assert.assertFalse(ctrl.isMonitoringTerminated()); ctrl.terminateMonitoring();
/** * This method represents the input port. The new records are send to the monitoring controller before they are * delivered via the output port. * * @param record * The next record. */ @Override protected void execute(final IMonitoringRecord record) { this.monitoringController.newMonitoringRecord(record); this.outputPort.send(record); }
protected void checkControllerStateAfterRecordsPassedToController( final IMonitoringController monitoringController) { Assert.assertTrue(monitoringController.isMonitoringEnabled()); monitoringController.disableMonitoring(); Assert.assertFalse(monitoringController.isMonitoringEnabled()); }
final long offset = 300; // i.e., 1st event after 300 ms final ScheduledSamplerJob samplerJob = monitoringController.schedulePeriodicSampler(samplingCounter, offset, period, TimeUnit.MILLISECONDS); monitoringController.removeScheduledSampler(samplerJob); Assert.assertEquals("Unexpected number of triggering events before removal", 3, numEventsAfterRemoval); monitoringController.terminateMonitoring();
/** * Test if the default configuration for adaptive monitoring really has an empty probe pattern. */ @Test public void testInitializationDefaultConfigLocation() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); Assert.assertFalse(ctrl.isMonitoringTerminated()); final List<String> list = ctrl.getProbePatternList(); Assert.assertTrue(list.isEmpty()); ctrl.terminateMonitoring(); }