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));
}
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);
}
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();
}
}
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()));
}
}
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) {
}
}
Aggregations