OpenTSDBWithStormQuerier extends AbstractTimeSeriesQuerier { @Override public Map<String, Map<Long, Double>> getRawMetrics(String metricName, String parameters, long from, long to) { Map<String, String> queryParams = parseParameters(parameters); URI targetUri = composeRawQueryParameters(metricName, queryParams, from, to); log.debug("Calling {} for querying metric", targetUri.toString()); List<Map<String, ?>> responseList = JsonClientUtil.getEntity(client.target(targetUri), List.class); if (responseList.isEmpty()) { return Collections.emptyMap(); } Map<String, Map<Long, Double>> ret = new HashMap<>(responseList.size()); for (Map<String, ?> responseMap : responseList) { String retrievedMetricName = buildMetricNameFromResp(responseMap); Map<String, Number> retrievedPoints = (Map<String, Number>) responseMap.get("dps"); Map<Long, Double> pointsForOutput; if (retrievedPoints == null || retrievedPoints.isEmpty()) { pointsForOutput = Collections.emptyMap(); } else { pointsForOutput = new HashMap<>(retrievedPoints.size()); for (Map.Entry<String, Number> timestampToValue : retrievedPoints.entrySet()) { pointsForOutput.put(Long.valueOf(timestampToValue.getKey()), timestampToValue.getValue().doubleValue()); } } ret.put(retrievedMetricName, pointsForOutput); } return ret; }  @Override void init(Map<String, String> conf); @Override Map<Long, Double> getTopologyLevelMetrics(String topologyName, String metricName, AggregateFunction aggrFunction, long from, long to); @Override Map<Long, Double> getMetrics(String topologyName, String componentId, String metricName, AggregateFunction aggrFunction, long from, long to); @Override Map<String, Map<Long, Double>> getRawMetrics(String metricName, String parameters, long from, long to); static final String QUERY_API_URL; }
@Test public void getRawMetrics() throws Exception { stubMetricUrl(); String metricName = "sum:sys.cpu.user[host=web01]"; String parameters = ""; long from = 1234L; long to = 5678L; Map<String, Map<Long, Double>> metrics = querier.getRawMetrics(metricName, parameters, from, to); assertResult(metrics.get("sys.cpu.user[host=web01]")); verify(getRequestedFor(urlPathEqualTo(TEST_QUERY_API_PATH)) .withQueryParam("m", equalTo("sum:sys.cpu.user[host=web01]")) .withQueryParam("start", equalTo("1234")) .withQueryParam("end", equalTo("5678"))); }