Search in sources :

Example 1 with Header

use of org.rrd4j.core.Header in project ddf by codice.

the class RrdJmxCollectorTest method collectData.

private void collectData(int numRrdStepIterations) throws Exception {
    String rrdFilename = jmxCollector.getRrdPath();
    rrdDb = new RrdDb(rrdFilename);
    Header header = rrdDb.getHeader();
    // Wait for "n" iterations of RRDB's sample rate, then see if MBean value was collected
    LOGGER.debug("Sleeping for {} seconds", header.getStep() * numRrdStepIterations);
    Thread.sleep((header.getStep() * numRrdStepIterations) * 1000);
    // LOGGER.debug(rrdDb.dump());
    long endTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() / 1000;
    // +1 because the fetch gets data for times inclusively, e.g.,
    // endTime=12345, so startTime=12345-4=12341,
    // then fetch data for timestamps 12341, 12342, 12343, 12344, 12345 (which is 5 values)
    long startTime = endTime - numRrdStepIterations + 1;
    LOGGER.debug("startTime = {}, endTime = {}", startTime, endTime);
    FetchRequest fetchRequest = rrdDb.createFetchRequest(ConsolFun.TOTAL, startTime, endTime);
    FetchData fetchData = fetchRequest.fetchData();
    double[] values = fetchData.getValues(dataSourceName);
    assertThat(values.length, is(numRrdStepIterations));
    logFetchData(fetchData, "TOTAL");
    fetchRequest = rrdDb.createFetchRequest(ConsolFun.AVERAGE, startTime, endTime);
    fetchData = fetchRequest.fetchData();
    values = fetchData.getValues(dataSourceName);
    assertThat(values.length, is(numRrdStepIterations));
    logFetchData(fetchData, "AVERAGE");
    fetchRequest = rrdDb.createFetchRequest(ConsolFun.MIN, startTime, endTime);
    fetchData = fetchRequest.fetchData();
    values = fetchData.getValues(dataSourceName);
    assertThat(values.length, is(numRrdStepIterations));
    logFetchData(fetchData, "MIN");
    fetchRequest = rrdDb.createFetchRequest(ConsolFun.MAX, startTime, endTime);
    fetchData = fetchRequest.fetchData();
    values = fetchData.getValues(dataSourceName);
    assertThat(values.length, is(numRrdStepIterations));
    logFetchData(fetchData, "MAX");
}
Also used : Header(org.rrd4j.core.Header) FetchRequest(org.rrd4j.core.FetchRequest) RrdDb(org.rrd4j.core.RrdDb) FetchData(org.rrd4j.core.FetchData)

Example 2 with Header

use of org.rrd4j.core.Header 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));
}
Also used : Datasource(org.rrd4j.core.Datasource) Archive(org.rrd4j.core.Archive) Header(org.rrd4j.core.Header) RrdDb(org.rrd4j.core.RrdDb) DsType(org.rrd4j.DsType) Test(org.junit.Test)

Example 3 with Header

use of org.rrd4j.core.Header 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());
}
Also used : Datasource(org.rrd4j.core.Datasource) Archive(org.rrd4j.core.Archive) Header(org.rrd4j.core.Header) RrdDb(org.rrd4j.core.RrdDb) DsType(org.rrd4j.DsType) Test(org.junit.Test)

Aggregations

Header (org.rrd4j.core.Header)3 RrdDb (org.rrd4j.core.RrdDb)3 Test (org.junit.Test)2 DsType (org.rrd4j.DsType)2 Archive (org.rrd4j.core.Archive)2 Datasource (org.rrd4j.core.Datasource)2 FetchData (org.rrd4j.core.FetchData)1 FetchRequest (org.rrd4j.core.FetchRequest)1