Search in sources :

Example 1 with MetricTimeSeries

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

the class FlowTest method getPending.

private static long getPending(Map<String, String> tags) throws Exception {
    MetricDataQuery metricDataQuery = new MetricDataQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, "system.queue.pending", AggregationFunction.SUM, tags, ImmutableList.<String>of());
    Collection<MetricTimeSeries> query = metricStore.query(metricDataQuery);
    if (query.isEmpty()) {
        return 0;
    }
    MetricTimeSeries timeSeries = Iterables.getOnlyElement(query);
    List<TimeValue> timeValues = timeSeries.getTimeValues();
    TimeValue timeValue = Iterables.getOnlyElement(timeValues);
    return timeValue.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 2 with MetricTimeSeries

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

the class DataCleansingMapReduceTest method getValidityMetrics.

// pass true to get the number of invalid records; pass false to get the number of valid records processed.
private long getValidityMetrics(boolean invalid) throws Exception {
    String metric = "user.records." + (invalid ? "invalid" : "valid");
    Map<String, String> tags = ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NamespaceId.DEFAULT.getNamespace(), Constants.Metrics.Tag.APP, DataCleansing.NAME, Constants.Metrics.Tag.MAPREDUCE, DataCleansingMapReduce.NAME);
    MetricDataQuery metricQuery = new MetricDataQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, metric, AggregationFunction.SUM, tags, ImmutableList.<String>of());
    Collection<MetricTimeSeries> result = getMetricsManager().query(metricQuery);
    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();
}
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 3 with MetricTimeSeries

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

the class LocalMRJobInfoFetcher method getAggregates.

private void getAggregates(Map<String, String> tags, Map<String, String> metricsToCounters, Map<String, Long> result) {
    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.<String>of());
    Collection<MetricTimeSeries> query = metricStore.query(metricDataQuery);
    // initialize elements to zero
    for (String counterName : metricsToCounters.values()) {
        result.put(counterName, 0L);
    }
    for (MetricTimeSeries metricTimeSeries : query) {
        List<TimeValue> timeValues = metricTimeSeries.getTimeValues();
        TimeValue timeValue = Iterables.getOnlyElement(timeValues);
        result.put(metricsToCounters.get(metricTimeSeries.getMetricName()), timeValue.getValue());
    }
}
Also used : AggregationFunction(co.cask.cdap.api.dataset.lib.cube.AggregationFunction) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) TimeValue(co.cask.cdap.api.dataset.lib.cube.TimeValue)

Example 4 with MetricTimeSeries

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

the class LocalMRJobInfoFetcher method queryGroupedAggregates.

// queries MetricStore for one metric across all tasks of a certain TaskType, using GroupBy InstanceId
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());
    }
}
Also used : AggregationFunction(co.cask.cdap.api.dataset.lib.cube.AggregationFunction) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) TimeValue(co.cask.cdap.api.dataset.lib.cube.TimeValue)

Example 5 with MetricTimeSeries

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

the class MetricsProcessorServiceTest method assertMetricsResult.

private void assertMetricsResult(MetricStore metricStore, Map<String, String> metricsContext, Map<String, Long> expected) {
    for (Map.Entry<String, Long> metric : expected.entrySet()) {
        Collection<MetricTimeSeries> queryResult = metricStore.query(new MetricDataQuery(0, Integer.MAX_VALUE, Integer.MAX_VALUE, metric.getKey(), AggregationFunction.SUM, metricsContext, ImmutableList.<String>of()));
        MetricTimeSeries timeSeries = Iterables.getOnlyElement(queryResult);
        List<TimeValue> timeValues = timeSeries.getTimeValues();
        TimeValue timeValue = Iterables.getOnlyElement(timeValues);
        Assert.assertEquals(String.format("Actual value of metric: %s does not match expected", metric.getKey()), metric.getValue().longValue(), timeValue.getValue());
    }
}
Also used : MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TimeValue(co.cask.cdap.api.dataset.lib.cube.TimeValue)

Aggregations

MetricTimeSeries (co.cask.cdap.api.metrics.MetricTimeSeries)24 MetricDataQuery (co.cask.cdap.api.metrics.MetricDataQuery)19 TimeValue (co.cask.cdap.api.dataset.lib.cube.TimeValue)13 AggregationFunction (co.cask.cdap.api.dataset.lib.cube.AggregationFunction)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)3 Function (com.google.common.base.Function)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Map (java.util.Map)2 AppWithWorker (co.cask.cdap.AppWithWorker)1 ObjectStore (co.cask.cdap.api.dataset.lib.ObjectStore)1 TimeSeries (co.cask.cdap.api.dataset.lib.cube.TimeSeries)1 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)1 MetricSearchQuery (co.cask.cdap.api.metrics.MetricSearchQuery)1 MetricStore (co.cask.cdap.api.metrics.MetricStore)1 MetricsContext (co.cask.cdap.api.metrics.MetricsContext)1 NoopMetricsContext (co.cask.cdap.api.metrics.NoopMetricsContext)1 TagValue (co.cask.cdap.api.metrics.TagValue)1