use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class PreviewDataStreamsTest method getTotalMetric.
private long getTotalMetric(Map<String, String> tags, String metricName, PreviewManager previewManager) {
MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, tags, new ArrayList<String>());
Collection<MetricTimeSeries> result = previewManager.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();
}
use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class MapReduceProgramRunnerTest method testMapReduceMetricsControl.
@Test
public void testMapReduceMetricsControl() throws Exception {
final ApplicationWithPrograms app = deployApp(Id.Namespace.fromEntityId(new NamespaceId("metrics_ns")), AppWithMapReduce.class);
Map<String, String> runtimeArguments = Maps.newHashMap();
// do not emit metrics for this app
runtimeArguments.put("metric", "metric");
runtimeArguments.put("startTs", "1");
runtimeArguments.put("stopTs", "3");
runtimeArguments.put("tag", "tag1");
// Do not emit metrics for mapreduce
runtimeArguments.put(SystemArguments.METRICS_ENABLED, "false");
runProgram(app, AppWithMapReduce.AggregateTimeseriesByTag.class, new BasicArguments(runtimeArguments));
Collection<MetricTimeSeries> metrics = getMetricTimeSeries();
Assert.assertEquals(0, metrics.size());
// emit metrics for mapreduce
runtimeArguments.put(SystemArguments.METRICS_ENABLED, "true");
runProgram(app, AppWithMapReduce.AggregateTimeseriesByTag.class, new BasicArguments(runtimeArguments));
metrics = getMetricTimeSeries();
Assert.assertTrue(metrics.size() > 0);
}
use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class AppFabricTestBase method getTotalMetric.
protected long getTotalMetric(String metricName, Map<String, String> tags) {
MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, "system." + metricName, AggregationFunction.SUM, tags, Collections.emptyList());
Collection<MetricTimeSeries> results = metricStore.query(query);
if (results.isEmpty()) {
return 0;
}
// since it is totals query and not groupBy specified, we know there's one time series
List<TimeValue> timeValues = results.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 io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class CDAPLoad method collect.
@Override
public void collect() throws IOException {
// reset all metrics
reset();
int currentTimeSecs = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
// We want metrics in the last hour
int startTimeSecs = currentTimeSecs - (60 * 60);
// We want to aggregate metrics in a sliding window of the past hour from the time the request is made.
// To do this, query metrics with the minute resolution, so you get 60 points, then aggregate on the client side.
// Not using hourly resolution here, because that wouldn't give aggregated metrics for the past hour, but
// just aggregated metrics for the current hour (if called 15 mins past the hour, it will only give an aggregated
// value for the past 15 mins).
Map<String, String> tags = Collections.singletonMap(Constants.Metrics.Tag.NAMESPACE, NamespaceId.SYSTEM.getEntityName());
Collection<MetricTimeSeries> metricTimeSeries = metricsSystemClient.query(startTimeSecs, currentTimeSecs, 60, tags, METRICS, Collections.emptySet());
for (MetricTimeSeries metricTimeSery : metricTimeSeries) {
switch(metricTimeSery.getMetricName()) {
case "system.request.received":
totalRequests = aggregateMetricValue(metricTimeSery);
break;
case "system.response.successful":
successful = aggregateMetricValue(metricTimeSery);
break;
case "system.response.client-error":
clientErrors = aggregateMetricValue(metricTimeSery);
break;
case "system.response.server-error":
serverErrors = aggregateMetricValue(metricTimeSery);
break;
case "system.services.log.error":
errorLogs = aggregateMetricValue(metricTimeSery);
break;
case "system.services.log.warn":
warnLogs = aggregateMetricValue(metricTimeSery);
break;
}
}
}
use of io.cdap.cdap.api.metrics.MetricTimeSeries in project cdap by cdapio.
the class CDAPTransactions method collect.
@Override
public void collect() throws Exception {
Collection<MetricTimeSeries> collection = metricsSystemClient.query(Constants.Metrics.TRANSACTION_MANAGER_CONTEXT, METRICS);
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);
}
Aggregations