Search in sources :

Example 16 with MetricTimeSeries

use of co.cask.cdap.api.metrics.MetricTimeSeries 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)

Example 17 with MetricTimeSeries

use of co.cask.cdap.api.metrics.MetricTimeSeries 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 18 with MetricTimeSeries

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

the class SparkTestRun method testSparkWithObjectStore.

@Test
public void testSparkWithObjectStore() throws Exception {
    ApplicationManager applicationManager = deploy(SparkAppUsingObjectStore.class);
    DataSetManager<ObjectStore<String>> keysManager = getDataset("keys");
    prepareInputData(keysManager);
    SparkManager sparkManager = applicationManager.getSparkManager(CharCountProgram.class.getSimpleName()).start();
    sparkManager.waitForRun(ProgramRunStatus.COMPLETED, 1, TimeUnit.MINUTES);
    DataSetManager<KeyValueTable> countManager = getDataset("count");
    checkOutputData(countManager);
    // validate that the table emitted metrics
    // one read + one write in beforeSubmit(), increment (= read + write) in main -> 4
    Tasks.waitFor(4L, new Callable<Long>() {

        @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);
}
Also used : ApplicationManager(co.cask.cdap.test.ApplicationManager) ObjectStore(co.cask.cdap.api.dataset.lib.ObjectStore) SparkAppUsingObjectStore(co.cask.cdap.spark.app.SparkAppUsingObjectStore) SparkManager(co.cask.cdap.test.SparkManager) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) IOException(java.io.IOException) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) Collection(java.util.Collection) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) Test(org.junit.Test)

Example 19 with MetricTimeSeries

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

the class CDAPTransactions method collect.

@Override
public void collect() throws Exception {
    Collection<MetricTimeSeries> collection = metricStore.query(new MetricDataQuery(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, METRICS, Constants.Metrics.TRANSACTION_MANAGER_CONTEXT, Collections.<String>emptyList(), null));
    for (MetricTimeSeries metricTimeSeries : collection) {
        if (metricTimeSeries.getMetricName().equals("system.committing.size")) {
            numCommittingChangeSets = (int) aggregateMetricValue(metricTimeSeries);
        }
        if (metricTimeSeries.getMetricName().equals("system.committed.size")) {
            numCommittedChangeSets = (int) aggregateMetricValue(metricTimeSeries);
        }
    }
    Transaction transaction = txClient.startShort();
    readPointer = transaction.getReadPointer();
    writePointer = transaction.getWritePointer();
    numInProgressTx = transaction.getInProgress().length;
    numInvalidTx = transaction.getInvalids().length;
    txClient.abort(transaction);
}
Also used : Transaction(org.apache.tephra.Transaction) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery)

Example 20 with MetricTimeSeries

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

the class MetricStoreRequestExecutor method queryTimeSeries.

private Iterator<TimeValue> queryTimeSeries(MetricDataQuery query) throws Exception {
    Collection<MetricTimeSeries> result = metricStore.query(query);
    if (result.size() == 0) {
        return new ArrayList<TimeValue>().iterator();
    }
    // since there's no group by condition, it'll return single time series always
    MetricTimeSeries timeSeries = result.iterator().next();
    return Iterables.transform(timeSeries.getTimeValues(), new Function<TimeValue, TimeValue>() {

        @Override
        public TimeValue apply(TimeValue input) {
            return new TimeValue(input.getTimestamp(), input.getValue());
        }
    }).iterator();
}
Also used : Function(com.google.common.base.Function) AggregationFunction(co.cask.cdap.api.dataset.lib.cube.AggregationFunction) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) 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