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();
}
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();
}
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());
}
}
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());
}
}
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());
}
}
Aggregations