Search in sources :

Example 41 with MetricDataQuery

use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.

the class PreviewDataPipelineTest method getTotalMetric.

private long getTotalMetric(Map<String, String> tags, String metricName, PreviewRunner runner) {
    MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, tags, new ArrayList<String>());
    Collection<MetricTimeSeries> result = runner.getMetricsQueryHelper().getMetricStore().query(query);
    if (result.isEmpty()) {
        return 0;
    }
    List<TimeValue> timeValues = result.iterator().next().getTimeValues();
    if (timeValues.isEmpty()) {
        return 0;
    }
    return timeValues.get(0).getValue();
}
Also used : MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) TimeValue(co.cask.cdap.api.dataset.lib.cube.TimeValue)

Example 42 with MetricDataQuery

use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.

the class PreviewDataStreamsTest method getTotalMetric.

private long getTotalMetric(Map<String, String> tags, String metricName, PreviewRunner runner) {
    MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, tags, new ArrayList<String>());
    Collection<MetricTimeSeries> result = runner.getMetricsQueryHelper().getMetricStore().query(query);
    if (result.isEmpty()) {
        return 0;
    }
    List<TimeValue> timeValues = result.iterator().next().getTimeValues();
    if (timeValues.isEmpty()) {
        return 0;
    }
    return timeValues.get(0).getValue();
}
Also used : MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) TimeValue(co.cask.cdap.api.dataset.lib.cube.TimeValue)

Aggregations

MetricDataQuery (co.cask.cdap.api.metrics.MetricDataQuery)42 Test (org.junit.Test)25 MetricTimeSeries (co.cask.cdap.api.metrics.MetricTimeSeries)21 TimeValue (co.cask.cdap.api.dataset.lib.cube.TimeValue)11 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)4 ApplicationManager (co.cask.cdap.test.ApplicationManager)4 AggregationFunction (co.cask.cdap.api.dataset.lib.cube.AggregationFunction)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Collection (java.util.Collection)3 ObjectStore (co.cask.cdap.api.dataset.lib.ObjectStore)2 MetricStore (co.cask.cdap.api.metrics.MetricStore)2 QueueName (co.cask.cdap.common.queue.QueueName)2 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)2 SparkAppUsingObjectStore (co.cask.cdap.spark.app.SparkAppUsingObjectStore)2 SparkManager (co.cask.cdap.test.SparkManager)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1