/** * {@inheritDoc} */ @Override public boolean canBeProcessed(DefaultData defaultData) { return !influxActive && (defaultData instanceof TimerData) && ((TimerData) defaultData).isCharting(); }
/** * {@inheritDoc} */ @Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (receiver instanceof TimerData) { TimerData timerData = (TimerData) receiver; if ("canChart".equals(property)) { if (expectedValue instanceof Boolean) { return ((Boolean) expectedValue).booleanValue() == timerData.isCharting(); } else { return false; } } } return false; }
/** * Check if the data if valid. We currently have following constraints: * * <ul> * <li>If {@link TimerData} instance then charting must be set * <li>If {@link JmxSensorValueData} instance then it must be boolean or numeric * </ul> * * @param defaultData * Data to check. * @return True if data should be used with the pointer and sent to influx. */ private boolean isValidData(DefaultData defaultData) { if ((defaultData instanceof TimerData) && !((TimerData) defaultData).isCharting()) { return false; } if ((defaultData instanceof JmxSensorValueData) && !((JmxSensorValueData) defaultData).isBooleanOrNumeric()) { return false; } if ((defaultData instanceof InvocationSequenceData) && (((InvocationSequenceData) defaultData).getParentSequence() != null)) { return false; } return true; }
@Test public void charting() { // set up data long platformId = 1L; long methodId = 3L; long sensorTypeId = 11L; Object object = mock(Object.class); Object[] parameters = new Object[2]; Object result = mock(Object.class); Double firstTimerValue = 1000.453d; Double secondTimerValue = 1323.675d; when(timer.getCurrentTime()).thenReturn(firstTimerValue).thenReturn(secondTimerValue); when(platformManager.getPlatformId()).thenReturn(platformId); when(registeredSensorConfig.getSettings()).thenReturn(Collections.<String, Object> singletonMap("charting", Boolean.TRUE)); timerHook.beforeBody(methodId, sensorTypeId, object, parameters, registeredSensorConfig); timerHook.firstAfterBody(methodId, sensorTypeId, object, parameters, result, false, registeredSensorConfig); timerHook.secondAfterBody(coreService, methodId, sensorTypeId, object, parameters, result, false, registeredSensorConfig); ArgumentCaptor<TimerData> captor = ArgumentCaptor.forClass(TimerData.class); verify(coreService).addDefaultData(captor.capture()); TimerData timerData = captor.getValue(); assertThat(timerData.isCharting(), is(true)); }
case CHARTING: return Boolean.valueOf(o1.isCharting()).compareTo(Boolean.valueOf(o2.isCharting())); default: return 0;
return isTimerSensorBounded(timerData) && timerData.isCharting(); } else if (selectedObject instanceof TimerData) { return isTimerSensorBounded((TimerData) selectedObject) && ((TimerData) selectedObject).isCharting();
when(timerData.isCharting()).thenReturn(false); when(httpTimerData.isCharting()).thenReturn(false); processor.process(timerData, entityManager); when(timerData.isCharting()).thenReturn(true); when(httpTimerData.isCharting()).thenReturn(true); processor.process(timerData, entityManager);
assertThat(timerData.getCpuMin(), is((secondCpuTimerValue - firstCpuTimerValue) / 1000000.0d)); assertThat(timerData.getCpuMax(), is((secondCpuTimerValue - firstCpuTimerValue) / 1000000.0d)); assertThat(timerData.isCharting(), is(true));
/** * {@inheritDoc} */ @Override public IAggregatedData<TimerData> getClone(TimerData timerData) { AggregatedTimerData clone = new AggregatedTimerData(); clone.setPlatformIdent(timerData.getPlatformIdent()); clone.setSensorTypeIdent(timerData.getSensorTypeIdent()); clone.setMethodIdent(timerData.getMethodIdent()); clone.setCharting(timerData.isCharting()); return clone; }
assertThat(timerData.getMin(), is(secondTimerValue - firstTimerValue)); assertThat(timerData.getMax(), is(secondTimerValue - firstTimerValue)); assertThat(timerData.isCharting(), is(true)); assertThat(timerData.getMin(), is(fourthTimerValue - thirdTimerValue)); assertThat(timerData.getMax(), is(fourthTimerValue - thirdTimerValue)); assertThat(timerData.isCharting(), is(true));
assertThat(timerData.getCpuMin(), is((thirdCpuTimerValue - secondCpuTimerValue) / 1000000.0d)); assertThat(timerData.getCpuMax(), is((thirdCpuTimerValue - secondCpuTimerValue) / 1000000.0d)); assertThat(timerData.isCharting(), is(false)); assertThat(timerData.getCpuMin(), is((fourthCpuTimerValue - firstCpuTimerValue) / 1000000.0d)); assertThat(timerData.getCpuMax(), is((fourthCpuTimerValue - firstCpuTimerValue) / 1000000.0d)); assertThat(timerData.isCharting(), is(false));
/** * Aggregates the values given in the supplied timer data parameter to the objects data. * * @param timerData * Data to be aggregated into current object. */ public void aggregateTimerData(TimerData timerData) { super.aggregateInvocationAwareData(timerData); this.setCount(this.getCount() + timerData.getCount()); this.setDuration(this.getDuration() + timerData.getDuration()); this.calculateMax(timerData.getMax()); this.calculateMin(timerData.getMin()); if (timerData.isCpuMetricDataAvailable()) { this.setCpuDuration(this.getCpuDuration() + timerData.getCpuDuration()); this.calculateCpuMax(timerData.getCpuMax()); this.calculateCpuMin(timerData.getCpuMin()); } if (timerData.isExclusiveTimeDataAvailable()) { this.addExclusiveDuration(timerData.getExclusiveDuration()); this.setExclusiveCount(this.getExclusiveCount() + timerData.getExclusiveCount()); this.calculateExclusiveMax(timerData.getExclusiveMax()); this.calculateExclusiveMin(timerData.getExclusiveMin()); } this.charting = this.charting | timerData.isCharting(); }