/** * Initializes the {@link IPlatformSensor}. * * @param sensorTypeConfig * initialization configuration. */ private void init(PlatformSensorTypeConfig sensorTypeConfig) { this.sensorTypeConfig = sensorTypeConfig; this.initSensorData(); }
/** * {@inheritDoc} */ @Override public void gather() { // The timestamp is set in the {@link RuntimeInformation#reset()} to avoid multiple renewal. // It will not be set on the first execution of {@link RuntimeInformation#gather()}, but // shortly before. long uptime = this.getRuntimeBean().getUptime(); this.runtimeInformationData.setUptime(uptime); }
@Test void countIsIncremented() { this.mockCollectorWithDefaults(); this.cut.gather(); this.cut.gather(); MemoryInformationData collector = (MemoryInformationData) this.cut.get(); assertThat(collector.getCount(), is(2)); } }
@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 comittedNonHeapMemorySizeIsCalculated() { this.mockCollectorWithDefaults(); MemoryUsage nonHeapMemoryUsage = this.memoryBean.getNonHeapMemoryUsage(); when(nonHeapMemoryUsage.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.getMinComittedNonHeapMemorySize(), is(9L)); assertThat(collector.getMaxComittedNonHeapMemorySize(), is(11L)); assertThat(collector.getTotalComittedNonHeapMemorySize(), is(40L)); }
/** * {@inheritDoc} */ @Override public void gather() { // The timestamp is set in the {@link CpuInformation#reset()} to avoid multiple renewal. It // will not be set on the first execution of {@link CpuInformation#gather()}, but shortly // before. float cpuUsage = this.getOsBean().retrieveCpuUsage(); long cpuTime = this.getOsBean().getProcessCpuTime(); this.cpuInformationData.incrementCount(); this.cpuInformationData.updateProcessCpuTime(cpuTime); this.cpuInformationData.addCpuUsage(cpuUsage); if (cpuUsage < this.cpuInformationData.getMinCpuUsage()) { this.cpuInformationData.setMinCpuUsage(cpuUsage); } if (cpuUsage > this.cpuInformationData.getMaxCpuUsage()) { this.cpuInformationData.setMaxCpuUsage(cpuUsage); } }
@Test void freeMemoryIsCalculated() { this.mockCollectorWithDefaults(); when(this.osBean.getFreePhysicalMemorySize()).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.getMinFreePhysMemory(), is(9L)); assertThat(collector.getMaxFreePhysMemory(), is(11L)); assertThat(collector.getTotalFreePhysMemory(), is(40L)); }
@Test void freeSwapSpaceIsCalculated() { this.mockCollectorWithDefaults(); when(this.osBean.getFreeSwapSpaceSize()).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.getMinFreeSwapSpace(), is(9L)); assertThat(collector.getMaxFreeSwapSpace(), is(11L)); assertThat(collector.getTotalFreeSwapSpace(), is(40L)); }
@Test void comittedVirtualMemSizeIsCalculated() { this.mockCollectorWithDefaults(); when(this.osBean.getCommittedVirtualMemorySize()).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.getMinComittedVirtualMemSize(), is(9L)); assertThat(collector.getMaxComittedVirtualMemSize(), is(11L)); assertThat(collector.getTotalComittedVirtualMemSize(), is(40L)); }
/** * {@inheritDoc} */ @Override public void gather() { // The timestamp is set in the {@link CompilationInformation#reset()} to avoid multiple // renewal. It will not be set on the first execution of // {@link CompilationInformation#gather()}, but shortly before. long totalCompilationTime = this.getRuntimeBean().getTotalCompilationTime(); this.compilationInformationData.incrementCount(); this.compilationInformationData.addTotalCompilationTime(totalCompilationTime); if (totalCompilationTime < this.compilationInformationData.getMinTotalCompilationTime()) { this.compilationInformationData.setMinTotalCompilationTime(totalCompilationTime); } else if (totalCompilationTime > this.compilationInformationData.getMaxTotalCompilationTime()) { this.compilationInformationData.setMaxTotalCompilationTime(totalCompilationTime); } }
@Test void getForTheFirstTime() { SystemInformationData systemInformationData = (SystemInformationData) this.cut.getSystemSensorData(); Object firstExecution = this.cut.get(); assertThat((SystemInformationData) firstExecution, is(systemInformationData)); }
/** * {@inheritDoc} */ @Override public void afterPropertiesSet() throws Exception { for (PlatformSensorTypeConfig config : configurationStorage.getPlatformSensorTypes()) { if (config.getClassName().equals(this.getClass().getName())) { this.init(config); break; } } }
/** * Initializes the {@link SystemSensorData}. */ private void initSensorData() { SystemSensorData systemSensorData = this.getSystemSensorData(); systemSensorData.setPlatformIdent(this.platformManager.getPlatformId()); systemSensorData.setSensorTypeIdent(sensorTypeConfig.getId()); }
@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)); }
@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)); }