use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.
the class RrdMetricsRetrieverTest method testMetricsCsvDataWithCounter.
@Test
public void testMetricsCsvDataWithCounter() throws Exception {
String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).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));
}
use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.
the class RrdMetricsRetrieverTest method testMetricsXlsDataWithCounter.
@Test
public void testMetricsXlsDataWithCounter() throws Exception {
String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).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, true);
} else {
fail();
}
}
use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.
the class RrdMetricsRetrieverTest method testMetricsGraphWithCounter.
@Test
public void testMetricsGraphWithCounter() throws Exception {
String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).build();
MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
byte[] metricsGraph = metricsRetriever.createGraph("Query Count", 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 Count", rrdFilename, START_TIME, endTime, "My Vertical Axis Label", "My Title");
assertThat(metricsGraph, not(nullValue()));
assertThat(metricsGraph.length, is(greaterThan(0)));
}
use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.
the class RrdMetricsRetrieverTest method testMetricsJsonDataWithGauge.
@Test
public void testMetricsJsonDataWithGauge() 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 json = metricsRetriever.createJsonData("queryCount", rrdFilename, START_TIME, endTime);
JSONParser parser = new JSONParser();
JSONObject jsonObj = (JSONObject) parser.parse(json);
// Verify the title, and data (i.e., samples) are present
assertThat(jsonObj.size(), equalTo(2));
assertThat(jsonObj.get("title"), 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()));
}
}
use of ddf.metrics.reporting.internal.MetricsRetriever in project ddf by codice.
the class RrdMetricsRetrieverTest method testMetricsPptDataWithCounter.
@Test
public void testMetricsPptDataWithCounter() throws Exception {
String rrdFilename = TEST_DIR + "queryCount_Counter" + RRD_FILE_EXTENSION;
long endTime = new RrdFileBuilder().rrdFileName(rrdFilename).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", true);
}
Aggregations