/** * {@inheritDoc} */ @Override public SystemSensorData get() { CpuInformationData newCpuInformationData = new CpuInformationData(); newCpuInformationData.setPlatformIdent(this.cpuInformationData.getPlatformIdent()); newCpuInformationData.setSensorTypeIdent(this.cpuInformationData.getSensorTypeIdent()); newCpuInformationData.setCount(this.cpuInformationData.getCount()); newCpuInformationData.setProcessCpuTime(this.cpuInformationData.getProcessCpuTime()); newCpuInformationData.setTotalCpuUsage(this.cpuInformationData.getTotalCpuUsage()); newCpuInformationData.setMinCpuUsage(this.cpuInformationData.getMinCpuUsage()); newCpuInformationData.setMaxCpuUsage(this.cpuInformationData.getMaxCpuUsage()); newCpuInformationData.setTimeStamp(this.cpuInformationData.getTimeStamp()); return newCpuInformationData; }
/** * {@inheritDoc} */ @Override public CpuInformationData getClone(CpuInformationData cpuInformationData) { CpuInformationData clone = new CpuInformationData(); clone.setPlatformIdent(cpuInformationData.getPlatformIdent()); clone.setSensorTypeIdent(cpuInformationData.getSensorTypeIdent()); return clone; }
/** * Updates the upper plot with the given input data. * * @param cpuData * The input data. */ private void addUpperPlotData(List<CpuInformationData> cpuData) { for (CpuInformationData data : cpuData) { float cpuAverage = data.getTotalCpuUsage() / data.getCount(); cpuUsage.add(data.getTimeStamp().getTime(), cpuAverage, data.getMinCpuUsage(), data.getMaxCpuUsage(), false); } cpuUsage.fireSeriesChanged(); }
@Test void cpuUsageIsSetForMinAndMaxOnTheFirstRun() { when(this.osBean.retrieveCpuUsage()).thenReturn(10f); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getMinCpuUsage(), is(10f)); assertThat(collector.getMaxCpuUsage(), is(10f)); assertThat(collector.getTotalCpuUsage(), is(10f)); }
/** * {@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); } }
/** * {@inheritDoc} */ @Override public void setInputDefinition(InputDefinition inputDefinition) { super.setInputDefinition(inputDefinition); template = new CpuInformationData(); template.setPlatformIdent(inputDefinition.getIdDefinition().getPlatformId()); template.setSensorTypeIdent(inputDefinition.getIdDefinition().getSensorTypeId()); template.setId(-1L); dataAccessService = inputDefinition.getRepositoryDefinition().getGlobalDataAccessService(); }
@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.CpuInformation.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))); }
/** * {@inheritDoc} */ @Override public void setInputDefinition(InputDefinition inputDefinition) { super.setInputDefinition(inputDefinition); cpuObj = new CpuInformationData(); cpuObj.setPlatformIdent(inputDefinition.getIdDefinition().getPlatformId()); dataAccessService = inputDefinition.getRepositoryDefinition().getGlobalDataAccessService(); }
processor.process(new CpuInformationData(), entityManager); verifyZeroInteractions(buffer, entityManager);
/** * {@inheritDoc} */ @Override public Object getAggregationKey(CpuInformationData object) { return object.getPlatformIdent(); }
@Test void countIsIncremented() { this.cut.gather(); this.cut.gather(); CpuInformationData collector = (CpuInformationData) 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());
/** * {@inheritDoc} */ @Override protected void addFields(CpuInformationData data, Builder builder) { float cpuAverage = data.getTotalCpuUsage() / data.getCount(); // fields builder.addField(Series.CpuInformation.FIELD_AVG_CPU_UTIL, cpuAverage); builder.addField(Series.CpuInformation.FIELD_MIN_CPU_UTIL, data.getMinCpuUsage()); builder.addField(Series.CpuInformation.FIELD_MAX_CPU_UTIL, data.getMaxCpuUsage()); }
@Test void cpuUsageIsCalculated() { when(this.osBean.retrieveCpuUsage()).thenReturn(10f).thenReturn(9f).thenReturn(11f).thenReturn(10f); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getMinCpuUsage(), is(9f)); assertThat(collector.getMaxCpuUsage(), is(11f)); assertThat(collector.getTotalCpuUsage(), is(40f)); }
/** * {@inheritDoc} */ @Override public void setInputDefinition(InputDefinition inputDefinition) { super.setInputDefinition(inputDefinition); long platformId = inputDefinition.getIdDefinition().getPlatformId(); systemObj = new SystemInformationData(); systemObj.setPlatformIdent(platformId); classLoadingObj = new ClassLoadingInformationData(); classLoadingObj.setPlatformIdent(platformId); cpuObj = new CpuInformationData(); cpuObj.setPlatformIdent(platformId); compilationObj = new CompilationInformationData(); compilationObj.setPlatformIdent(platformId); memoryObj = new MemoryInformationData(); memoryObj.setPlatformIdent(platformId); runtimeObj = new RuntimeInformationData(); runtimeObj.setPlatformIdent(platformId); threadObj = new ThreadInformationData(); threadObj.setPlatformIdent(platformId); dataAccessService = inputDefinition.getRepositoryDefinition().getGlobalDataAccessService(); }
processor.process(new CpuInformationData(), entityManager); verifyZeroInteractions(log, indexingTree, entityManager);
@Test void getNewCpuInformationData() throws Exception { CpuInformationData collector = (CpuInformationData) this.cut.getSystemSensorData(); collector.setCount(1); collector.setPlatformIdent(2L); collector.setSensorTypeIdent(3L); collector.setProcessCpuTime(4L); collector.setTotalCpuUsage(5f); collector.setMaxCpuUsage(6f); collector.setMinCpuUsage(7f); collector.setTimeStamp(new Timestamp(8L)); CpuInformationData cpuInformationData = (CpuInformationData) this.cut.get(); assertThat(cpuInformationData.getCount(), is(1)); assertThat(cpuInformationData.getPlatformIdent(), is(2L)); assertThat(cpuInformationData.getSensorTypeIdent(), is(3L)); assertThat(cpuInformationData.getProcessCpuTime(), is(4L)); assertThat(cpuInformationData.getTotalCpuUsage(), is(5f)); assertThat(cpuInformationData.getMaxCpuUsage(), is(6f)); assertThat(cpuInformationData.getMinCpuUsage(), is(7f)); assertThat(cpuInformationData.getTimeStamp().getTime(), is(8L)); } }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getCount()).thenReturn(5); when(data.getTotalCpuUsage()).thenReturn(RandomUtils.nextFloat()); when(data.getMinCpuUsage()).thenReturn(RandomUtils.nextFloat()); when(data.getMaxCpuUsage()).thenReturn(RandomUtils.nextFloat()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.CpuInformation.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(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_AVG_CPU_UTIL, (Object) Double.valueOf(data.getTotalCpuUsage() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_MAX_CPU_UTIL, (Object) Double.valueOf(data.getMaxCpuUsage()))); assertThat(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_MIN_CPU_UTIL, (Object) Double.valueOf(data.getMinCpuUsage()))); }
@Test void collectorClassIsResetted() throws Exception { CpuInformationData collector = (CpuInformationData) this.cut.getSystemSensorData(); collector.setCount(1); collector.setPlatformIdent(2L); collector.setSensorTypeIdent(3L); collector.setProcessCpuTime(4L); collector.setTotalCpuUsage(5f); collector.setMaxCpuUsage(6f); collector.setMinCpuUsage(7f); collector.setTimeStamp(new Timestamp(8L)); this.cut.reset(); CpuInformationData cpuInformationData = (CpuInformationData) this.cut.get(); assertThat(cpuInformationData.getCount(), is(0)); assertThat(cpuInformationData.getPlatformIdent(), is(2L)); assertThat(cpuInformationData.getSensorTypeIdent(), is(3L)); assertThat(cpuInformationData.getProcessCpuTime(), is(0L)); assertThat(cpuInformationData.getTotalCpuUsage(), is(0f)); assertThat(cpuInformationData.getMaxCpuUsage(), is(0f)); assertThat(cpuInformationData.getMinCpuUsage(), is(Float.MAX_VALUE)); assertThat(cpuInformationData.getTimeStamp().getTime(), is(not(8L))); } }