GraphiteMetricSource implements MetricSource { @Override public List<MetricSourceResult> getMetricData(String metricTags) { GraphiteProperties props = BeanUtil.getBean(GraphiteProperties.class); Map<String, Object> params = Collections.singletonMap("tags", metricTags); GraphiteResult[] graphiteResult = restTemplate.getForObject(props.getUrlTemplate(), GraphiteResult[].class, params); List<MetricSourceResult> results = new ArrayList<>(); if (graphiteResult.length != 0) { String[][] dataPoints = graphiteResult[0].getDatapoints(); for (String[] dataPoint : dataPoints) { double dataPointValue = 0.0; long epochSeconds = Long.parseLong(dataPoint[1]); if (dataPoint[0] != null) { dataPointValue = Double.parseDouble(dataPoint[0]); } MetricSourceResult result = new MetricSourceResult(dataPointValue, epochSeconds); results.add(result); } } return results; }  @Override List<MetricSourceResult> getMetricData(String metricTags);  }
@Test public void testGetMetricData() { List<MetricSourceResult> metricSourceResults = graphiteMetricSource.getMetricData("metricKey"); assertNotNull(metricSourceResults); assertEquals(2, metricSourceResults.size()); }