/** * Gets {@link #maxValue}. * * @return {@link #maxValue} */ public double getMaxValue() { if (aggregationCount <= 0) { return getValueAsDouble(); } return maxValue; }
/** * Calculates and returns the average value of the aggregated objects. * * @return the average value */ public double getAverageValue() { if (aggregationCount <= 0) { return getValueAsDouble(); } return totalValue / aggregationCount; }
/** * Gets {@link #minValue}. * * @return {@link #minValue} */ public double getMinValue() { if (aggregationCount <= 0) { return getValueAsDouble(); } return minValue; }
/** * {@inheritDoc} */ @Override protected void addFields(JmxSensorValueData data, Builder builder) { // fields builder.addField(Series.Jmx.FIELD_VALUE, data.getValueAsDouble()); }
/** * {@inheritDoc} */ @Override public void aggregate(JmxSensorValueData data) { if (!data.isBooleanOrNumeric()) { throw new RuntimeException("The given JMX data can not be aggregated."); } aggregationCount++; double valueToAggregate = data.getValueAsDouble(); minValue = Math.min(minValue, valueToAggregate); maxValue = Math.max(maxValue, valueToAggregate); totalValue += valueToAggregate; }
/** * Sets the {@link #value}. * * @param value * New value for {@link #value}. */ public void setValue(String value) { this.value = value; if ((aggregationCount <= 0) && isBooleanOrNumeric()) { double currentValue = getValueAsDouble(); aggregationCount = 1; minValue = currentValue; maxValue = currentValue; totalValue = currentValue; } }
@Test public void noJmxIdent() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getJmxDefinitionDataIdentForId(JMX_IDENT)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getJmxSensorDefinitionDataIdentId()).thenReturn(JMX_IDENT); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Jmx.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Jmx.TAG_JMX_ATTRIBUTE_FULL_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.Jmx.FIELD_VALUE, (Object) data.getValueAsDouble())); }
@Test public void noPlatform() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); when(cachedDataService.getJmxDefinitionDataIdentForId(JMX_IDENT)).thenReturn(jmxDefinitionDataIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getJmxSensorDefinitionDataIdentId()).thenReturn(JMX_IDENT); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Jmx.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), not(hasKey(Series.TAG_AGENT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.Jmx.FIELD_VALUE, (Object) data.getValueAsDouble())); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getJmxDefinitionDataIdentForId(JMX_IDENT)).thenReturn(jmxDefinitionDataIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getJmxSensorDefinitionDataIdentId()).thenReturn(JMX_IDENT); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getValueAsDouble()).thenReturn(RandomUtils.nextDouble()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Jmx.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.Jmx.TAG_JMX_ATTRIBUTE_FULL_NAME, String.valueOf(JMX_ATTR))); assertThat(getFields(pointBuilder), hasEntry(Series.Jmx.FIELD_VALUE, (Object) data.getValueAsDouble())); }