Search in sources :

Example 1 with StreamSizeNotification

use of co.cask.cdap.common.stream.notification.StreamSizeNotification in project cdap by caskdata.

the class StreamSizeSchedulerTest method createMetricsPublisher.

@Override
protected StreamMetricsPublisher createMetricsPublisher(final StreamId streamId) {
    final NotificationFeedId feed = new NotificationFeedId(streamId.getNamespace(), Constants.Notification.Stream.STREAM_FEED_CATEGORY, streamId.getStream() + "Size");
    return new StreamMetricsPublisher() {

        long totalSize;

        @Override
        public void increment(long size) throws Exception {
            metricStore.add(new MetricValues(ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, streamId.getNamespace(), Constants.Metrics.Tag.STREAM, streamId.getStream()), "collect.bytes", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()), size, MetricType.COUNTER));
            totalSize += size;
            notificationService.publish(feed, new StreamSizeNotification(System.currentTimeMillis(), totalSize));
        }
    };
}
Also used : NotificationFeedId(co.cask.cdap.proto.id.NotificationFeedId) MetricValues(co.cask.cdap.api.metrics.MetricValues) StreamSizeNotification(co.cask.cdap.common.stream.notification.StreamSizeNotification)

Aggregations

MetricValues (co.cask.cdap.api.metrics.MetricValues)1 StreamSizeNotification (co.cask.cdap.common.stream.notification.StreamSizeNotification)1 NotificationFeedId (co.cask.cdap.proto.id.NotificationFeedId)1