/** * Returns the date of the latest element in the {@link #loadedData} list. * * @return Date of the latest loaded {@link JmxSensorValueData} */ private Date getLatestLoadedElementDate() { if (CollectionUtils.isEmpty(loadedData)) { return null; } long max = Long.MIN_VALUE; for (JmxSensorValueData data : loadedData) { if (data.getTimeStamp().getTime() > max) { max = data.getTimeStamp().getTime(); } } return new Date(max); }
/** * Returns a list containing {@link JmxSensorValueData} objects which were created between the * {@code from} and {@code to} date. * * @param from * Objects have to be created after this date * @param to * Objects have to be created before this date * @return List containing {@link JmxSensorValueData} objects */ private List<JmxSensorValueData> selectChartingData(Date from, Date to) { List<JmxSensorValueData> resultList = new ArrayList<>(); Date fromShifted = new Date(from.getTime() - 1); Date toShifted = new Date(to.getTime() + 1); for (JmxSensorValueData jmxData : loadedData) { if (jmxData.getTimeStamp().after(fromShifted) && jmxData.getTimeStamp().before(toShifted)) { resultList.add(jmxData); } } return adjustSamplingRate(resultList, fromShifted, toShifted, aggregator); }
/** * {@inheritDoc} */ @Override public String toString() { return "JmxSensorValueData [jmxSensorDefinitionDataIdent=" + jmxSensorDefinitionDataIdentId + ", value=" + value + ", getId()=" + getId() + ", getPlatformIdent()=" + getPlatformIdent() + ", getSensorTypeIdent()=" + getSensorTypeIdent() + ", getTimeStamp()=" + getTimeStamp() + "]"; }
@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())); }
/** * Copy constructor. Copies all values (except the aggregation values) of the given * {@link JmxSensorValueData} object into the newly created. * * @param origin * object to clone */ public JmxSensorValueData(JmxSensorValueData origin) { setId(origin.getId()); setPlatformIdent(origin.getPlatformIdent()); setTimeStamp(new Timestamp(origin.getTimeStamp().getTime())); setSensorTypeIdent(origin.getSensorTypeIdent()); setJmxSensorDefinitionDataIdentId(origin.jmxSensorDefinitionDataIdentId); setValue(origin.value); }
@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())); }
JmxSensorValueData jmxData = (JmxSensorValueData) data; if (map.containsKey(jmxData.getJmxSensorDefinitionDataIdentId())) { if (map.get(jmxData.getJmxSensorDefinitionDataIdentId()).getTimeStamp().getTime() < data.getTimeStamp().getTime()) { map.put(jmxData.getJmxSensorDefinitionDataIdentId(), (JmxSensorValueData) data);
@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())); }
/** * Returns the styled text for a specific column. * * @param jmxDefinitionDataIdent * The object to extract the information from. * @param data * The object to extract the value information from. * @param enumId * The enumeration ID. * @return The styled string containing the information from the data object. */ private StyledString getStyledTextForColumn(JmxDefinitionDataIdent jmxDefinitionDataIdent, JmxSensorValueData data, Column enumId) { switch (enumId) { case DOMAINNAME: return new StyledString(jmxDefinitionDataIdent.getDerivedDomainName()); case TYPENAME: return new StyledString(jmxDefinitionDataIdent.getDerivedTypeName()); case ATTRIBUTE: return new StyledString(jmxDefinitionDataIdent.getmBeanAttributeName()); case TIMESTAMP: return new StyledString(NumberFormatter.formatTime(data.getTimeStamp())); case VALUE: return new StyledString(data.getValue()); case CHARTING: return emptyStyledString; default: return new StyledString("error"); } }