MemoryInformationData newMemoryInformationData = new MemoryInformationData(); newMemoryInformationData.setPlatformIdent(this.memoryInformationData.getPlatformIdent()); newMemoryInformationData.setSensorTypeIdent(this.memoryInformationData.getSensorTypeIdent()); newMemoryInformationData.setCount(this.memoryInformationData.getCount()); newMemoryInformationData.setTotalFreePhysMemory(this.memoryInformationData.getTotalFreePhysMemory()); newMemoryInformationData.setMinFreePhysMemory(this.memoryInformationData.getMinFreePhysMemory()); newMemoryInformationData.setMaxFreePhysMemory(this.memoryInformationData.getMaxFreePhysMemory()); newMemoryInformationData.setTotalFreeSwapSpace(this.memoryInformationData.getTotalFreeSwapSpace()); newMemoryInformationData.setMinFreeSwapSpace(this.memoryInformationData.getMinFreeSwapSpace()); newMemoryInformationData.setMaxFreeSwapSpace(this.memoryInformationData.getMaxFreeSwapSpace()); newMemoryInformationData.setTotalComittedVirtualMemSize(this.memoryInformationData.getTotalComittedVirtualMemSize()); newMemoryInformationData.setMinComittedVirtualMemSize(this.memoryInformationData.getMinComittedVirtualMemSize()); newMemoryInformationData.setMaxComittedVirtualMemSize(this.memoryInformationData.getMaxComittedVirtualMemSize()); newMemoryInformationData.setTotalUsedHeapMemorySize(this.memoryInformationData.getTotalUsedHeapMemorySize()); newMemoryInformationData.setMinUsedHeapMemorySize(this.memoryInformationData.getMinUsedHeapMemorySize()); newMemoryInformationData.setMaxUsedHeapMemorySize(this.memoryInformationData.getMaxUsedHeapMemorySize()); newMemoryInformationData.setTotalComittedHeapMemorySize(this.memoryInformationData.getTotalComittedHeapMemorySize()); newMemoryInformationData.setMinComittedHeapMemorySize(this.memoryInformationData.getMinComittedHeapMemorySize()); newMemoryInformationData.setMaxComittedHeapMemorySize(this.memoryInformationData.getMaxComittedHeapMemorySize()); newMemoryInformationData.setTotalUsedNonHeapMemorySize(this.memoryInformationData.getTotalUsedNonHeapMemorySize()); newMemoryInformationData.setMinUsedNonHeapMemorySize(this.memoryInformationData.getMinUsedNonHeapMemorySize()); newMemoryInformationData.setMaxUsedNonHeapMemorySize(this.memoryInformationData.getMaxUsedNonHeapMemorySize());
/** * {@inheritDoc} */ @Override public MemoryInformationData getClone(MemoryInformationData memoryInformationData) { MemoryInformationData clone = new MemoryInformationData(); clone.setPlatformIdent(memoryInformationData.getPlatformIdent()); clone.setSensorTypeIdent(memoryInformationData.getSensorTypeIdent()); return clone; }
/** * Updates the upper plot with the given input data. * * @param memoryData * the input data. */ private void addUpperPlotData(List<MemoryInformationData> memoryData) { for (MemoryInformationData data : memoryData) { long usedHeapMemoryAvg = (data.getTotalUsedHeapMemorySize() / data.getCount()) / 1024; heapMemory.add(data.getTimeStamp().getTime(), usedHeapMemoryAvg, data.getMinUsedHeapMemorySize() / 1024.0d, data.getMaxUsedHeapMemorySize() / 1024.0d, false); } heapMemory.fireSeriesChanged(); }
int count = data.getCount(); long freePhysMemory = 0; if (data.getTotalFreePhysMemory() > 0) { freePhysMemory = data.getTotalFreePhysMemory() / count; if (data.getTotalFreeSwapSpace() > 0) { freeSwapSpace = data.getTotalFreeSwapSpace() / count; if (data.getTotalComittedHeapMemorySize() > 0) { committedHeapMemorySize = data.getTotalComittedHeapMemorySize() / count; if (data.getTotalComittedNonHeapMemorySize() > 0) { committedNonHeapMemorySize = data.getTotalComittedNonHeapMemorySize() / count; if (data.getTotalUsedHeapMemorySize() > 0) { usedHeapMemorySize = data.getTotalUsedHeapMemorySize() / count; if (data.getTotalUsedNonHeapMemorySize() > 0) { usedNonHeapMemorySize = data.getTotalUsedNonHeapMemorySize() / count; builder.addField(Series.MemoryInformation.FIELD_AVG_COMMITTED_NON_HEAP_MEMORY, committedNonHeapMemorySize); builder.addField(Series.MemoryInformation.FIELD_AVG_USED_HEAP_MEMORY, usedHeapMemorySize); builder.addField(Series.MemoryInformation.FIELD_MIN_USED_HEAP_MEMORY, data.getMinUsedHeapMemorySize()); builder.addField(Series.MemoryInformation.FIELD_MAX_USED_HEAP_MEMORY, data.getMaxUsedHeapMemorySize()); builder.addField(Series.MemoryInformation.FIELD_AVG_USED_NON_HEAP_MEMORY, usedNonHeapMemorySize); builder.addField(Series.MemoryInformation.FIELD_MIN_USED_NON_HEAP_MEMORY, data.getMinUsedNonHeapMemorySize()); builder.addField(Series.MemoryInformation.FIELD_MAX_USED_NON_HEAP_MEMORY, data.getMaxUsedNonHeapMemorySize());
this.memoryInformationData.incrementCount(); this.memoryInformationData.addFreePhysMemory(freePhysMemory); this.memoryInformationData.addFreeSwapSpace(freeSwapSpace); this.memoryInformationData.addComittedVirtualMemSize(comittedVirtualMemSize); this.memoryInformationData.addUsedHeapMemorySize(usedHeapMemorySize); this.memoryInformationData.addComittedHeapMemorySize(comittedHeapMemorySize); this.memoryInformationData.addUsedNonHeapMemorySize(usedNonHeapMemorySize); this.memoryInformationData.addComittedNonHeapMemorySize(comittedNonHeapMemorySize); if (freePhysMemory < this.memoryInformationData.getMinFreePhysMemory()) { this.memoryInformationData.setMinFreePhysMemory(freePhysMemory); } else if (freePhysMemory > this.memoryInformationData.getMaxFreePhysMemory()) { this.memoryInformationData.setMaxFreePhysMemory(freePhysMemory); if (freeSwapSpace < this.memoryInformationData.getMinFreeSwapSpace()) { this.memoryInformationData.setMinFreeSwapSpace(freeSwapSpace); } else if (freeSwapSpace > this.memoryInformationData.getMaxFreeSwapSpace()) { this.memoryInformationData.setMaxFreeSwapSpace(freeSwapSpace); if (comittedVirtualMemSize < this.memoryInformationData.getMinComittedVirtualMemSize()) { this.memoryInformationData.setMinComittedVirtualMemSize(comittedVirtualMemSize); } else if (comittedVirtualMemSize > this.memoryInformationData.getMaxComittedVirtualMemSize()) { this.memoryInformationData.setMaxComittedVirtualMemSize(comittedVirtualMemSize); if (usedHeapMemorySize < this.memoryInformationData.getMinUsedHeapMemorySize()) { this.memoryInformationData.setMinUsedHeapMemorySize(usedHeapMemorySize); } else if (usedHeapMemorySize > this.memoryInformationData.getMaxUsedHeapMemorySize()) { this.memoryInformationData.setMaxUsedHeapMemorySize(usedHeapMemorySize);
/** * Updates the lower plot with the given input data. * * @param memoryData * the input data. */ private void addLowerPlotData(List<MemoryInformationData> memoryData) { for (MemoryInformationData data : memoryData) { // TODO adjust the fractional part long usedNonHeapMemoryAvg = (data.getTotalUsedNonHeapMemorySize() / data.getCount()) / 1024; nonHeapMemory.add(data.getTimeStamp().getTime(), usedNonHeapMemoryAvg, data.getMinUsedNonHeapMemorySize() / 1024.0d, data.getMaxUsedNonHeapMemorySize() / 1024.0d, false); } nonHeapMemory.fireSeriesChanged(); }
@Test void usedHeapMemorySizeIsCalculated() { this.mockCollectorWithDefaults(); MemoryUsage heapMemoryUsage = this.memoryBean.getHeapMemoryUsage(); when(heapMemoryUsage.getUsed()).thenReturn(10L).thenReturn(9L).thenReturn(11L).thenReturn(10L); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); MemoryInformationData collector = (MemoryInformationData) this.cut.get(); assertThat(collector.getMinUsedHeapMemorySize(), is(9L)); assertThat(collector.getMaxUsedHeapMemorySize(), is(11L)); assertThat(collector.getTotalUsedHeapMemorySize(), is(40L)); }
@Test void usedNonHeapMemorySizeIsCalculated() { this.mockCollectorWithDefaults(); MemoryUsage nonHeapMemoryUsage = this.memoryBean.getNonHeapMemoryUsage(); when(nonHeapMemoryUsage.getUsed()).thenReturn(10L).thenReturn(9L).thenReturn(11L).thenReturn(10L); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); MemoryInformationData collector = (MemoryInformationData) this.cut.get(); assertThat(collector.getMinUsedNonHeapMemorySize(), is(9L)); assertThat(collector.getMaxUsedNonHeapMemorySize(), is(11L)); assertThat(collector.getTotalUsedNonHeapMemorySize(), is(40L)); }
@Test public void noPlatform() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getCount()).thenReturn(1); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.MemoryInformation.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))); }
@Test void comittedHeapMemorySizeIsCalculated() { this.mockCollectorWithDefaults(); MemoryUsage heapMemoryUsage = this.memoryBean.getHeapMemoryUsage(); when(heapMemoryUsage.getCommitted()).thenReturn(10L).thenReturn(9L).thenReturn(11L).thenReturn(10L); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); MemoryInformationData collector = (MemoryInformationData) this.cut.get(); assertThat(collector.getMinComittedHeapMemorySize(), is(9L)); assertThat(collector.getMaxComittedHeapMemorySize(), is(11L)); assertThat(collector.getTotalComittedHeapMemorySize(), is(40L)); }
/** * {@inheritDoc} */ @Override public Object getAggregationKey(MemoryInformationData object) { return object.getPlatformIdent(); }
@Test void countIsIncremented() { this.mockCollectorWithDefaults(); this.cut.gather(); this.cut.gather(); MemoryInformationData collector = (MemoryInformationData) this.cut.get(); assertThat(collector.getCount(), is(2)); } }
Date dataNewestDate = new Date(0); if (!oldData.isEmpty()) { dataNewestDate = oldData.get(oldData.size() - 1).getTimeStamp(); if (newestDate.before(data.get(data.size() - 1).getTimeStamp())) { newestDate = new Date(data.get(data.size() - 1).getTimeStamp().getTime()); oldData.addAll(rightData); oldToDate = (Date) to.clone(); if (newestDate.before(rightData.get(rightData.size() - 1).getTimeStamp())) { newestDate = new Date(rightData.get(rightData.size() - 1).getTimeStamp().getTime()); oldData.addAll(timerData); oldToDate = (Date) to.clone(); if (newestDate.before(timerData.get(timerData.size() - 1).getTimeStamp())) { newestDate = new Date(timerData.get(timerData.size() - 1).getTimeStamp().getTime());
when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getCount()).thenReturn(5); when(data.getTotalFreePhysMemory()).thenReturn(0L); when(data.getTotalFreeSwapSpace()).thenReturn(0L); when(data.getTotalComittedHeapMemorySize()).thenReturn(0L); when(data.getTotalComittedNonHeapMemorySize()).thenReturn(0L); when(data.getTotalUsedHeapMemorySize()).thenReturn(0L); when(data.getTotalUsedNonHeapMemorySize()).thenReturn(0L); when(data.getMinUsedHeapMemorySize()).thenReturn(0L); when(data.getMaxUsedHeapMemorySize()).thenReturn(0L); when(data.getMinUsedNonHeapMemorySize()).thenReturn(0L); when(data.getMaxUsedNonHeapMemorySize()).thenReturn(0L); 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(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_HEAP_MEMORY, (Object) (data.getTotalComittedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_NON_HEAP_MEMORY, (Object) (data.getTotalComittedNonHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_PHYS_MEMORY, (Object) (data.getTotalFreePhysMemory() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_SWAP_SPACE, (Object) (data.getTotalFreeSwapSpace() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_HEAP_MEMORY, (Object) (data.getTotalUsedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_NON_HEAP_MEMORY, (Object) (data.getTotalUsedNonHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MAX_USED_HEAP_MEMORY, (Object) data.getMaxUsedHeapMemorySize())); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MIN_USED_HEAP_MEMORY, (Object) data.getMinUsedHeapMemorySize())); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MAX_USED_NON_HEAP_MEMORY, (Object) data.getMaxUsedNonHeapMemorySize())); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MIN_USED_NON_HEAP_MEMORY, (Object) data.getMinUsedNonHeapMemorySize()));
collector.setPlatformIdent(1L); collector.setSensorTypeIdent(2L); collector.setCount(3); collector.setTotalFreePhysMemory(4L); collector.setMinFreePhysMemory(5L); collector.setMaxFreePhysMemory(6L); collector.setTotalFreeSwapSpace(7L); collector.setMinFreeSwapSpace(8L); collector.setMaxFreeSwapSpace(9L); collector.setTotalComittedVirtualMemSize(10L); collector.setMinComittedVirtualMemSize(11L); collector.setMaxComittedVirtualMemSize(12L); collector.setTotalUsedHeapMemorySize(13L); collector.setMinUsedHeapMemorySize(14L); collector.setMaxUsedHeapMemorySize(15L); collector.setTotalComittedHeapMemorySize(16L); collector.setMinComittedHeapMemorySize(17L); collector.setMaxComittedHeapMemorySize(18L); collector.setTotalUsedNonHeapMemorySize(19L); collector.setMinUsedNonHeapMemorySize(20L); collector.setMaxUsedNonHeapMemorySize(21L); collector.setMinComittedNonHeapMemorySize(22L);
when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getCount()).thenReturn(5); when(data.getTotalFreePhysMemory()).thenReturn(RandomUtils.nextLong()); when(data.getTotalFreeSwapSpace()).thenReturn(RandomUtils.nextLong()); when(data.getTotalComittedHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getTotalComittedNonHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getTotalUsedHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getTotalUsedNonHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getMinUsedHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getMaxUsedHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getMinUsedNonHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getMaxUsedNonHeapMemorySize()).thenReturn(RandomUtils.nextLong()); 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(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_HEAP_MEMORY, (Object) (data.getTotalComittedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_NON_HEAP_MEMORY, (Object) (data.getTotalComittedNonHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_PHYS_MEMORY, (Object) (data.getTotalFreePhysMemory() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_SWAP_SPACE, (Object) (data.getTotalFreeSwapSpace() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_HEAP_MEMORY, (Object) (data.getTotalUsedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_NON_HEAP_MEMORY, (Object) (data.getTotalUsedNonHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MAX_USED_HEAP_MEMORY, (Object) data.getMaxUsedHeapMemorySize())); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MIN_USED_HEAP_MEMORY, (Object) data.getMinUsedHeapMemorySize())); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MAX_USED_NON_HEAP_MEMORY, (Object) data.getMaxUsedNonHeapMemorySize())); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_MIN_USED_NON_HEAP_MEMORY, (Object) data.getMinUsedNonHeapMemorySize()));
collector.setPlatformIdent(1L); collector.setSensorTypeIdent(2L); collector.setCount(3); collector.setTotalFreePhysMemory(4L); collector.setMinFreePhysMemory(5L); collector.setMaxFreePhysMemory(6L); collector.setTotalFreeSwapSpace(7L); collector.setMinFreeSwapSpace(8L); collector.setMaxFreeSwapSpace(9L); collector.setTotalComittedVirtualMemSize(10L); collector.setMinComittedVirtualMemSize(11L); collector.setMaxComittedVirtualMemSize(12L); collector.setTotalUsedHeapMemorySize(13L); collector.setMinUsedHeapMemorySize(14L); collector.setMaxUsedHeapMemorySize(15L); collector.setTotalComittedHeapMemorySize(16L); collector.setMinComittedHeapMemorySize(17L); collector.setMaxComittedHeapMemorySize(18L); collector.setTotalUsedNonHeapMemorySize(19L); collector.setMinUsedNonHeapMemorySize(20L); collector.setMaxUsedNonHeapMemorySize(21L); collector.setMinComittedNonHeapMemorySize(22L);