Search in sources :

Example 1 with MetricsRetriever

use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.

the class RrdMetricsRetrieverTest method testMetricsCsvDataWithGauge.

@Test
public void testMetricsCsvDataWithGauge() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Gauge" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).dsType(DsType.GAUGE).build();
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    String csv = metricsRetriever.createCsvData(rrdFilename, START_TIME, endTime);
    // Break up CSV data into its individual lines
    // Each line should have 2 parts (cells)
    // The first line should be the column headers
    String[] csvLines = csv.split("\n");
    // Verify that number of lines should be the column headers + (number of samples - 1)
    // Since 3 samples were taken, but only 2 are added to the RRD file due to averaging,
    // expect 2 lines of data and the one line of column headers.
    assertThat(csvLines.length, equalTo(7));
    // column headers
    assertThat(csvLines[0], equalTo("Timestamp,Value"));
    String[] cells = csvLines[1].split(",");
    // each line of data has the 2 values
    assertThat(cells.length, equalTo(2));
}
Also used : MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 2 with MetricsRetriever

use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.

the class RrdMetricsRetrieverTest method testMetricsPptReport.

@Test
public void testMetricsPptReport() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
    new RrdFileBuilder().rrdFileName(rrdFilename).build();
    rrdFilename = TEST_DIR + "queryCount_Gauge" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).dsType(DsType.GAUGE).build();
    List<String> metricNames = new ArrayList<String>();
    metricNames.add("queryCount_Counter");
    metricNames.add("queryCount_Gauge");
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    OutputStream os = metricsRetriever.createPptReport(metricNames, TEST_DIR, START_TIME, endTime);
    InputStream is = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
    assertThat(is, not(nullValue()));
    SlideShow ppt = new SlideShow(is);
    Slide[] slides = ppt.getSlides();
    assertThat(slides.length, equalTo(2));
    verifySlide(slides[0], "queryCount_Counter", true);
    verifySlide(slides[1], "queryCount_Gauge", false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) Slide(org.apache.poi.hslf.model.Slide) SlideShow(org.apache.poi.hslf.usermodel.SlideShow) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 3 with MetricsRetriever

use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.

the class RrdMetricsRetrieverTest method testMetricsXlsDataWithGauge.

@Test
public void testMetricsXlsDataWithGauge() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Gauge" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).dsType(DsType.GAUGE).build();
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    OutputStream os = metricsRetriever.createXlsData("queryCount", rrdFilename, START_TIME, endTime);
    InputStream xls = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
    assertThat(xls, not(nullValue()));
    HSSFWorkbook wb = new HSSFWorkbook(xls);
    assertThat(wb.getNumberOfSheets(), equalTo(1));
    HSSFSheet sheet = wb.getSheet("Query Count");
    if (null != sheet) {
        assertThat(sheet, not(nullValue()));
        verifyWorksheet(sheet, "Query Count", 6, false);
    } else {
        fail();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 4 with MetricsRetriever

use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.

the class RrdMetricsRetrieverTest method testMetricsJsonDataWithCounter.

@Test
public void testMetricsJsonDataWithCounter() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).build();
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    String json = metricsRetriever.createJsonData("queryCount", rrdFilename, START_TIME, endTime);
    JSONParser parser = new JSONParser();
    JSONObject jsonObj = (JSONObject) parser.parse(json);
    // Verify the title, totalCount, and data (i.e., samples) are present
    assertThat(jsonObj.size(), equalTo(3));
    assertThat(jsonObj.get("title"), not(nullValue()));
    assertThat(jsonObj.get("totalCount"), not(nullValue()));
    // Verify 2 samples were retrieved from the RRD file and put in the JSON fetch results
    JSONArray samples = (JSONArray) jsonObj.get("data");
    // 6 because that's the max num rows configured for
    assertThat(samples.size(), equalTo(6));
    // Verify each retrieved sample has a timestamp and value
    for (int i = 0; i < samples.size(); i++) {
        JSONObject sample = (JSONObject) samples.get(i);
        LOGGER.debug("timestamp = {},   value= {}", (String) sample.get("timestamp"), sample.get("value"));
        assertThat(sample.get("timestamp"), not(nullValue()));
        assertThat(sample.get("value"), not(nullValue()));
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) JSONParser(org.json.simple.parser.JSONParser) Test(org.junit.Test)

Example 5 with MetricsRetriever

use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.

the class RrdMetricsRetrieverTest method testRrdFileWithMultipleDataSources.

@Test
public // (expected = MetricsGraphException.class)
void testRrdFileWithMultipleDataSources() throws Exception {
    String rrdFilename = TEST_DIR + "dummy" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).numSamples(4).secondDataSource(true).build();
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    try {
        metricsRetriever.createGraph("Dummy", rrdFilename, START_TIME, endTime);
        fail();
    } catch (MetricsGraphException e) {
    }
}
Also used : MetricsGraphException(ddf.metrics.reporting.internal.MetricsGraphException) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Aggregations

MetricsRetriever (ddf.metrics.reporting.internal.MetricsRetriever)17 Test (org.junit.Test)17 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)4 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)4 ArrayList (java.util.ArrayList)3 Slide (org.apache.poi.hslf.model.Slide)3 SlideShow (org.apache.poi.hslf.usermodel.SlideShow)3 MetricsGraphException (ddf.metrics.reporting.internal.MetricsGraphException)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 DateTime (org.joda.time.DateTime)1