private Map<String, Long> getTotalsWithSingleGroupByTag(MetricDataQuery query) throws Exception { // query must have resolution set to Integer.MAX_VALUE (i.e. "totals") Collection<MetricTimeSeries> result = metricStore.query(query); Map<String, Long> map = Maps.newHashMap(); for (MetricTimeSeries timeSeries : result) { // we know there's only ony group by tag String groupByTagValue = timeSeries.getTagValues().values().iterator().next(); // since it is totals, it will have only one TimeValue map.put(groupByTagValue, timeSeries.getTimeValues().get(0).getValue()); } return map; } }
private void queryGroupedAggregates(Map<String, String> tags, Table<String, String, Long> allTaskMetrics, Map<String, String> metricsToCounters) { Map<String, AggregationFunction> metrics = Maps.newHashMap(); // all map-reduce metrics are gauges for (String metric : metricsToCounters.keySet()) { metrics.put(metric, AggregationFunction.LATEST); } MetricDataQuery metricDataQuery = new MetricDataQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, metrics, tags, ImmutableList.of(Constants.Metrics.Tag.INSTANCE_ID)); Collection<MetricTimeSeries> query = metricStore.query(metricDataQuery); for (MetricTimeSeries metricTimeSeries : query) { List<TimeValue> timeValues = metricTimeSeries.getTimeValues(); TimeValue timeValue = Iterables.getOnlyElement(timeValues); String taskId = metricTimeSeries.getTagValues().get(Constants.Metrics.Tag.INSTANCE_ID); allTaskMetrics.put(taskId, metricsToCounters.get(metricTimeSeries.getMetricName()), timeValue.getValue()); } } }
private void queryGroupedAggregates(Map<String, String> tags, Table<String, String, Long> allTaskMetrics, Map<String, String> metricsToCounters) { Map<String, AggregationFunction> metrics = Maps.newHashMap(); // all map-reduce metrics are gauges for (String metric : metricsToCounters.keySet()) { metrics.put(metric, AggregationFunction.LATEST); } MetricDataQuery metricDataQuery = new MetricDataQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, metrics, tags, ImmutableList.of(Constants.Metrics.Tag.INSTANCE_ID)); Collection<MetricTimeSeries> query = metricStore.query(metricDataQuery); for (MetricTimeSeries metricTimeSeries : query) { List<TimeValue> timeValues = metricTimeSeries.getTimeValues(); TimeValue timeValue = Iterables.getOnlyElement(timeValues); String taskId = metricTimeSeries.getTagValues().get(Constants.Metrics.Tag.INSTANCE_ID); allTaskMetrics.put(taskId, metricsToCounters.get(metricTimeSeries.getMetricName()), timeValue.getValue()); } } }
private MetricQueryResult decorate(Collection<MetricTimeSeries> series, long startTs, long endTs, int resolution) { MetricQueryResult.TimeSeries[] serieses = new MetricQueryResult.TimeSeries[series.size()]; int i = 0; for (MetricTimeSeries timeSeries : series) { MetricQueryResult.TimeValue[] timeValues = decorate(timeSeries.getTimeValues()); serieses[i++] = new MetricQueryResult.TimeSeries(timeSeries.getMetricName(), tagNamesToHuman(timeSeries.getTagValues()), timeValues); } return new MetricQueryResult(startTs, endTs, serieses, resolution); }
private MetricQueryResult decorate(Collection<MetricTimeSeries> series, long startTs, long endTs, int resolution) { MetricQueryResult.TimeSeries[] serieses = new MetricQueryResult.TimeSeries[series.size()]; int i = 0; for (MetricTimeSeries timeSeries : series) { MetricQueryResult.TimeValue[] timeValues = decorate(timeSeries.getTimeValues()); serieses[i++] = new MetricQueryResult.TimeSeries(timeSeries.getMetricName(), tagNamesToHuman(timeSeries.getTagValues()), timeValues); } return new MetricQueryResult(startTs, endTs, serieses, resolution); }