use of org.rrd4j.core.Archive in project ddf by codice.
the class RrdJmxCollectorTest method testRrdFileCreationForGaugeDataSource.
@Test
public void testRrdFileCreationForGaugeDataSource() throws Exception {
// Set sample rate to 1 sec (default is 60 seconds) so that unit test runs quickly
String mbeanAttributeName = "Uptime";
String metricName = name.getMethodName();
int sampleRate = 1;
createJmxCollector(mbeanAttributeName, metricName, RrdJmxCollector.GAUGE_DATA_SOURCE_TYPE, sampleRate);
String rrdFilename = jmxCollector.getRrdPath();
assertThat(rrdFilename, is(TEST_DIR + metricName + RrdJmxCollector.RRD_FILENAME_SUFFIX));
rrdDb = new RrdDb(rrdFilename);
assertThat(rrdDb, not(nullValue()));
assertThat(rrdDb.isClosed(), is(false));
Header header = rrdDb.getHeader();
assertThat(header, not(nullValue()));
assertThat(header.getStep(), is((long) sampleRate));
assertThat(rrdDb.getDsCount(), is(1));
Datasource dataSource = rrdDb.getDatasource(dataSourceName);
assertThat(dataSource, not(nullValue()));
DsType dataSourceType = dataSource.getType();
assertThat(dataSourceType, is(DsType.GAUGE));
assertThat(rrdDb.getArcCount(), is(8));
Archive archive = rrdDb.getArchive(ConsolFun.MIN, 1);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(60));
archive = rrdDb.getArchive(ConsolFun.MIN, 15);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(RrdJmxCollector.ONE_YEAR_IN_15_MINUTE_STEPS));
archive = rrdDb.getArchive(ConsolFun.MAX, 1);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(60));
archive = rrdDb.getArchive(ConsolFun.MAX, 15);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(RrdJmxCollector.ONE_YEAR_IN_15_MINUTE_STEPS));
archive = rrdDb.getArchive(ConsolFun.AVERAGE, 1);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(60));
archive = rrdDb.getArchive(ConsolFun.AVERAGE, 15);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(RrdJmxCollector.ONE_YEAR_IN_15_MINUTE_STEPS));
}
use of org.rrd4j.core.Archive in project ddf by codice.
the class RrdJmxCollectorTest method testRrdFileCreationForDeriveDataSource.
@Test
public void testRrdFileCreationForDeriveDataSource() throws Exception {
// Set sample rate to 1 sec (default is 60 seconds) so that unit test runs quickly
String mbeanAttributeName = "Uptime";
String metricName = name.getMethodName();
int sampleRate = 1;
createJmxCollector(mbeanAttributeName, metricName, RrdJmxCollector.DERIVE_DATA_SOURCE_TYPE, sampleRate);
String rrdFilename = jmxCollector.getRrdPath();
assertThat(rrdFilename, is(TEST_DIR + metricName + RrdJmxCollector.RRD_FILENAME_SUFFIX));
rrdDb = new RrdDb(rrdFilename);
assertThat(rrdDb, not(nullValue()));
assertThat(rrdDb.isClosed(), is(false));
Header header = rrdDb.getHeader();
assertThat(header, not(nullValue()));
assertThat(header.getStep(), is((long) sampleRate));
assertThat(rrdDb.getDsCount(), is(1));
Datasource dataSource = rrdDb.getDatasource(dataSourceName);
assertThat(dataSource, not(nullValue()));
DsType dataSourceType = dataSource.getType();
assertThat(dataSourceType, is(DsType.DERIVE));
assertThat(rrdDb.getArcCount(), is(8));
Archive archive = rrdDb.getArchive(ConsolFun.AVERAGE, 1);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(60));
archive = rrdDb.getArchive(ConsolFun.AVERAGE, 15);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(RrdJmxCollector.ONE_YEAR_IN_15_MINUTE_STEPS));
archive = rrdDb.getArchive(ConsolFun.TOTAL, 1);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(60));
archive = rrdDb.getArchive(ConsolFun.TOTAL, 15);
assertThat(archive, not(nullValue()));
assertThat(archive.getRows(), is(RrdJmxCollector.ONE_YEAR_IN_15_MINUTE_STEPS));
// LOGGER.debug(rrdDb.dump());
}