private long getTotalCounter(Map<String, String> context, String metricName) throws Exception { MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, context, new ArrayList<String>()); try { Collection<MetricTimeSeries> result = getMetricsManager().query(query); if (result.isEmpty()) { return 0; } // since it is totals query and not groupBy specified, we know there's one time series List<TimeValue> timeValues = result.iterator().next().getTimeValues(); if (timeValues.isEmpty()) { return 0; } // since it is totals, we know there's one value only return timeValues.get(0).getValue(); } catch (Exception e) { throw Throwables.propagate(e); } } }
@Override public Long call() throws Exception { Collection<MetricTimeSeries> metrics = getMetricsManager().query(new MetricDataQuery( 0, System.currentTimeMillis() / 1000L, Integer.MAX_VALUE, "system." + Constants.Metrics.Name.Dataset.OP_COUNT, AggregationFunction.SUM, ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, DefaultId.NAMESPACE.getNamespace(), Constants.Metrics.Tag.APP, SparkAppUsingObjectStore.class.getSimpleName(), Constants.Metrics.Tag.SPARK, CharCountProgram.class.getSimpleName(), Constants.Metrics.Tag.DATASET, "totals"), Collections.<String>emptyList())); if (metrics.isEmpty()) { return 0L; } Assert.assertEquals(1, metrics.size()); MetricTimeSeries ts = metrics.iterator().next(); Assert.assertEquals(1, ts.getTimeValues().size()); return ts.getTimeValues().get(0).getValue(); } }, 10L, TimeUnit.SECONDS, 50L, TimeUnit.MILLISECONDS);
Collection<MetricTimeSeries> metrics = getMetricsManager().query( new MetricDataQuery( 0, System.currentTimeMillis() / 1000, Integer.MAX_VALUE,
"system.context.pool.size", AggregationFunction.MAX, context, Collections.emptyList()); Iterator<MetricTimeSeries> result = getMetricsManager().query(metricQuery).iterator(); return result.hasNext() ? result.next().getTimeValues().get(0).getValue() : 0L; }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);