Search in sources :

Example 6 with MetricsRetriever

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

the class RrdMetricsRetrieverTest method testMetricsXmlDataWithGauge.

@Test
public void testMetricsXmlDataWithGauge() 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 xml = metricsRetriever.createXmlData("queryCount", rrdFilename, START_TIME, endTime);
    assertXpathExists("/queryCount", xml);
    assertXpathExists("/queryCount/title", xml);
    assertXpathExists("/queryCount/data", xml);
    assertXpathExists("/queryCount/data/sample", xml);
    assertXpathExists("/queryCount/data/sample/timestamp", xml);
    assertXpathExists("/queryCount/data/sample/value", xml);
    assertXpathNotExists("/queryCount/data/totalCount", xml);
}
Also used : MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 7 with MetricsRetriever

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

the class RrdMetricsRetrieverTest method testMetricsPptDataWithGauge.

@Test
public void testMetricsPptDataWithGauge() 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.createPptData("queryCount", rrdFilename, 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(1));
    verifySlide(slides[0], "queryCount", false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Slide(org.apache.poi.hslf.model.Slide) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SlideShow(org.apache.poi.hslf.usermodel.SlideShow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 8 with MetricsRetriever

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

the class RrdMetricsRetrieverTest method testMetricsXlsReportSummary.

@Test
public void testMetricsXlsReportSummary() throws Exception {
    String metricName = "queryCount_Gauge";
    long endTime = new DateTime(DateTimeZone.UTC).getMillis();
    List<String> metricNames = new ArrayList<String>();
    metricNames.add(metricName);
    for (RrdMetricsRetriever.SUMMARY_INTERVALS interval : RrdMetricsRetriever.SUMMARY_INTERVALS.values()) {
        long startTime = 0L;
        switch(interval) {
            case minute:
                startTime = new DateTime(DateTimeZone.UTC).minusHours(1).getMillis();
                break;
            case hour:
                startTime = new DateTime(DateTimeZone.UTC).minusDays(1).getMillis();
                break;
            case day:
                startTime = new DateTime(DateTimeZone.UTC).minusWeeks(1).getMillis();
                break;
            case week:
                startTime = new DateTime(DateTimeZone.UTC).minusMonths(1).getMillis();
                break;
            case month:
                startTime = new DateTime(DateTimeZone.UTC).minusYears(1).getMillis();
                break;
        }
        int sampleSize = (int) ((endTime - startTime) / (RRD_STEP * 1000));
        new RrdFileBuilder().rrdFileName(TEST_DIR + metricName + RRD_FILE_EXTENSION).dsType(DsType.GAUGE).numSamples(sampleSize).numRows(sampleSize).startTime(startTime).build();
        MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
        OutputStream os = metricsRetriever.createXlsReport(metricNames, TEST_DIR, startTime, endTime, interval.toString());
        InputStream xls = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
        assertThat(xls, not(nullValue()));
        HSSFWorkbook wb = new HSSFWorkbook(xls);
        assertThat(wb.getNumberOfSheets(), equalTo(1));
        HSSFSheet sheet = wb.getSheetAt(0);
        assertThat(sheet, not(nullValue()));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) ByteArrayInputStream(java.io.ByteArrayInputStream) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Test(org.junit.Test)

Example 9 with MetricsRetriever

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

the class RrdMetricsRetrieverTest method testInvalidDataSourceType.

@Test
public // (expected = MetricsGraphException.class)
void testInvalidDataSourceType() throws Exception {
    String rrdFilename = TEST_DIR + "dummy_Absolute" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).numSamples(4).dsType(DsType.ABSOLUTE).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)

Example 10 with MetricsRetriever

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

the class RrdMetricsRetrieverTest method testMetricsXmlDataWithCounter.

@Test
public void testMetricsXmlDataWithCounter() throws Exception {
    String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
    long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).build();
    MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
    String xml = metricsRetriever.createXmlData("queryCount", rrdFilename, START_TIME, endTime);
    assertXpathExists("/queryCount", xml);
    assertXpathExists("/queryCount/title", xml);
    assertXpathExists("/queryCount/data", xml);
    assertXpathExists("/queryCount/data/sample", xml);
    assertXpathExists("/queryCount/data/sample/timestamp", xml);
    assertXpathExists("/queryCount/data/sample/value", xml);
    assertXpathExists("/queryCount/data/totalCount", xml);
}
Also used : 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