Search in sources :

Example 16 with MetricsRetriever

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

the class RrdMetricsRetrieverTest method testMetricsGraphWithGauge.

@Test
public void testMetricsGraphWithGauge() 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();
    byte[] metricsGraph = metricsRetriever.createGraph("Query Reponse Time", rrdFilename, START_TIME, endTime);
    assertThat(metricsGraph, not(nullValue()));
    assertThat(metricsGraph.length, is(greaterThan(0)));
    // NOTE: RrdGraph provides no way to programmatically verify the title and axis label were
    // set, i.e., no getters
    // All we can verify is that this alternate createGraph() method returns a byte array of the
    // graph image. Only
    // visual inspection can verify the graph's accurracy, title, and axis labels.
    metricsGraph = metricsRetriever.createGraph("Query Reponse Time", rrdFilename, START_TIME, endTime, "My Vertical Axis Label", "My Title");
    assertThat(metricsGraph, not(nullValue()));
    assertThat(metricsGraph.length, is(greaterThan(0)));
}
Also used : MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) Test(org.junit.Test)

Example 17 with MetricsRetriever

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

the class RrdMetricsRetrieverTest method testMetricsXlsReport.

@Test
public void testMetricsXlsReport() 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.createXlsReport(metricNames, TEST_DIR, START_TIME, endTime, null);
    InputStream xls = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
    assertThat(xls, not(nullValue()));
    HSSFWorkbook wb = new HSSFWorkbook(xls);
    assertThat(wb.getNumberOfSheets(), equalTo(2));
    HSSFSheet sheet = wb.getSheetAt(0);
    assertThat(sheet, not(nullValue()));
    verifyWorksheet(sheet, wb.getSheetName(0), 6, true);
    sheet = wb.getSheetAt(1);
    assertThat(sheet, not(nullValue()));
    verifyWorksheet(sheet, wb.getSheetName(1), 6, false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) MetricsRetriever(ddf.metrics.reporting.internal.MetricsRetriever) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) 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