Search in sources :

Example 16 with MetricValues

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

the class MetricsMessageCallback method addProcessingStats.

private void addProcessingStats(List<MetricValues> records, long now) {
    if (records.isEmpty()) {
        return;
    }
    int count = records.size();
    long delay = now - TimeUnit.SECONDS.toMillis(records.get(records.size() - 1).getTimestamp());
    records.add(new MetricValues(metricsContext, TimeUnit.MILLISECONDS.toSeconds(now), ImmutableList.of(new MetricValue("metrics.process.count", MetricType.COUNTER, count), new MetricValue("metrics.process.delay.ms", MetricType.GAUGE, delay))));
}
Also used : MetricValue(co.cask.cdap.api.metrics.MetricValue) MetricValues(co.cask.cdap.api.metrics.MetricValues)

Example 17 with MetricValues

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

the class MessagingMetricsCollectionServiceTest method checkReceivedMetrics.

protected void checkReceivedMetrics(Table<String, String, Long> expected, Map<String, MetricValues> actual) {
    for (String expectedContext : expected.rowKeySet()) {
        MetricValues metricValues = actual.get(expectedContext);
        Assert.assertNotNull("Missing expected value for " + expectedContext, metricValues);
        for (Map.Entry<String, Long> entry : expected.row(expectedContext).entrySet()) {
            boolean found = false;
            for (MetricValue metricValue : metricValues.getMetrics()) {
                if (entry.getKey().equals(metricValue.getName())) {
                    Assert.assertEquals(entry.getValue().longValue(), metricValue.getValue());
                    found = true;
                    break;
                }
            }
            Assert.assertTrue(found);
        }
    }
}
Also used : MetricValue(co.cask.cdap.api.metrics.MetricValue) MetricValues(co.cask.cdap.api.metrics.MetricValues) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 18 with MetricValues

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

the class MessagingMetricsCollectionServiceTest method testMessagingPublish.

@Test
public void testMessagingPublish() throws UnsupportedTypeException, InterruptedException, TopicNotFoundException, IOException {
    MetricsCollectionService collectionService = new MessagingMetricsCollectionService(TOPIC_PREFIX, PARTITION_SIZE, CConfiguration.create(), messagingService, recordWriter);
    collectionService.startAndWait();
    // publish metrics for different context
    for (int i = 1; i <= 3; i++) {
        collectionService.getContext(ImmutableMap.of("tag", "" + i)).increment("processed", i);
    }
    collectionService.stopAndWait();
    // <Context, metricName, value>
    Table<String, String, Long> expected = HashBasedTable.create();
    expected.put("tag.1", "processed", 1L);
    expected.put("tag.2", "processed", 2L);
    expected.put("tag.3", "processed", 3L);
    ReflectionDatumReader<MetricValues> recordReader = new ReflectionDatumReader<>(schema, metricValueType);
    assertMetricsFromMessaging(schema, recordReader, expected);
}
Also used : MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) ReflectionDatumReader(co.cask.cdap.internal.io.ReflectionDatumReader) MetricValues(co.cask.cdap.api.metrics.MetricValues) Test(org.junit.Test)

Aggregations

MetricValues (co.cask.cdap.api.metrics.MetricValues)18 MetricValue (co.cask.cdap.api.metrics.MetricValue)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 MetricDeleteQuery (co.cask.cdap.api.metrics.MetricDeleteQuery)2 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)2 ByteBufferInputStream (co.cask.common.io.ByteBufferInputStream)2 IOException (java.io.IOException)2 CubeFact (co.cask.cdap.api.dataset.lib.cube.CubeFact)1 MeasureType (co.cask.cdap.api.dataset.lib.cube.MeasureType)1 Measurement (co.cask.cdap.api.dataset.lib.cube.Measurement)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 MetricsContext (co.cask.cdap.api.metrics.MetricsContext)1 StreamSizeNotification (co.cask.cdap.common.stream.notification.StreamSizeNotification)1 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)1 RawMessage (co.cask.cdap.messaging.data.RawMessage)1 NotificationFeedId (co.cask.cdap.proto.id.NotificationFeedId)1 TopicId (co.cask.cdap.proto.id.TopicId)1 LoadingCache (com.google.common.cache.LoadingCache)1