Java Code Examples for backtype.storm.task.TopologyContext#registerMetric()

The following examples show how to use backtype.storm.task.TopologyContext#registerMetric() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CorrelationSpout.java    From eagle with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("open method invoked");
    }
    this.conf = conf;
    this.context = context;
    this.collector = collector;
    this.taskIndex = context.getThisTaskIndex();

    // initialize an empty SpoutSpec
    cachedSpoutSpec = new SpoutSpec(topologyId, new HashMap<>(), new HashMap<>(), new HashMap<>());

    changeNotifyService.registerListener(this);
    changeNotifyService.init(config, MetadataType.SPOUT);

    // register KafkaSpout metric
    kafkaSpoutMetric = new KafkaSpoutMetric();
    context.registerMetric("kafkaSpout", kafkaSpoutMetric, 60);

    this.serializer = Serializers.newPartitionedEventSerializer(this);
}
 
Example 2
Source File: BlackholeBlockingQueueSpout.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Map conf, TopologyContext context,
        SpoutOutputCollector _collector) {
    collector = _collector;
    _spoutMetric = new CountMetric();
    context.registerMetric(CatMetricUtil.getSpoutMetricName(topic, group),  
            _spoutMetric, Constants.EMIT_FREQUENCY_IN_SECONDS);
    
    ConsumerConfig config = new ConsumerConfig();
    try {
        consumer = new Consumer(topic, group, config);
    } catch (LionException e) {
        throw new RuntimeException(e);
    }
    consumer.start();
    stream = consumer.getStream();
    
    fetchThread = new MessageFetcher(stream);
    new Thread(fetchThread).start();
}
 
Example 3
Source File: BlackholeSpout.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Map conf, TopologyContext context,
        SpoutOutputCollector _collector) {
    collector = _collector;
    _spoutMetric = new CountMetric();
    context.registerMetric(CatMetricUtil.getSpoutMetricName(topic, group),  
            _spoutMetric, Constants.EMIT_FREQUENCY_IN_SECONDS);
    
    ConsumerConfig config = new ConsumerConfig();
    try {
        consumer = new Consumer(topic, group, config);
    } catch (LionException e) {
        throw new RuntimeException(e);
    }
    consumer.start();
    stream = consumer.getStream();
}
 
Example 4
Source File: AlertPublisherBolt.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void internalPrepare(OutputCollector collector, IMetadataChangeNotifyService coordinatorService, Config config, TopologyContext context) {
    coordinatorService.registerListener(this);
    coordinatorService.init(config, MetadataType.ALERT_PUBLISH_BOLT);
    this.alertPublisher.init(config, stormConf);
    streamContext = new StreamContextImpl(config, context.registerMetric("eagle.publisher", new MultiCountMetric(), 60), context);
    this.context = context;
    this.alertTemplateEngine = AlertTemplateProvider.createAlertTemplateEngine();
    this.alertTemplateEngine.init(config);
    this.alertFilter = new PipeStreamFilter(new AlertContextEnrichFilter(this), new AlertTemplateFilter(alertTemplateEngine));
}
 
Example 5
Source File: StreamRouterBolt.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void internalPrepare(OutputCollector collector, IMetadataChangeNotifyService changeNotifyService, Config config, TopologyContext context) {
    streamContext = new StreamContextImpl(config, context.registerMetric("eagle.router", new MultiCountMetric(), 60), context);
    routeCollector = new StreamRouterBoltOutputCollector(getBoltId(), new StormOutputCollector(collector, serializer), this.getOutputStreamIds(), streamContext);
    router.prepare(streamContext, routeCollector);
    changeNotifyService.registerListener(this);
    changeNotifyService.init(config, MetadataType.STREAM_ROUTER_BOLT);
}
 
Example 6
Source File: AlertBolt.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void internalPrepare(OutputCollector collector, IMetadataChangeNotifyService metadataChangeNotifyService, Config config, TopologyContext context) {
    // instantiate output lock object
    outputLock = new Object();
    streamContext = new StreamContextImpl(config, context.registerMetric("eagle.evaluator", new MultiCountMetric(), 60), context);
    alertOutputCollector = new AlertBoltOutputCollectorWrapper(new StormOutputCollector(collector), outputLock, streamContext);
    policyGroupEvaluator.init(streamContext, alertOutputCollector);
    metadataChangeNotifyService.registerListener(this);
    metadataChangeNotifyService.init(config, MetadataType.ALERT_BOLT);
}
 
Example 7
Source File: PythonShellMetricsSpout.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    super.open(conf, context, collector);

    CountShellMetric cMetric = new CountShellMetric();
    context.registerMetric("my-custom-shellspout-metric", cMetric, 5);
}
 
Example 8
Source File: TridentKafkaEmitter.java    From storm-kafka-0.8-plus with Apache License 2.0 5 votes vote down vote up
public TridentKafkaEmitter(Map conf, TopologyContext context, TridentKafkaConfig config, String topologyInstanceId) {
    _config = config;
    _topologyInstanceId = topologyInstanceId;
    _connections = new DynamicPartitionConnections(_config, KafkaUtils.makeBrokerReader(conf, _config));
    _topologyName = (String) conf.get(Config.TOPOLOGY_NAME);
    _kafkaOffsetMetric = new KafkaUtils.KafkaOffsetMetric(_config.topic, _connections);
    context.registerMetric("kafkaOffset", _kafkaOffsetMetric, _config.metricsTimeBucketSizeInSecs);
    _kafkaMeanFetchLatencyMetric = context.registerMetric("kafkaFetchAvg", new MeanReducer(), _config.metricsTimeBucketSizeInSecs);
    _kafkaMaxFetchLatencyMetric = context.registerMetric("kafkaFetchMax", new MaxMetric(), _config.metricsTimeBucketSizeInSecs);
}
 
Example 9
Source File: SystemBolt.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare(final Map stormConf, TopologyContext context, OutputCollector collector) {
    if (_prepareWasCalled && !"local".equals(stormConf.get(Config.STORM_CLUSTER_MODE))) {
        throw new RuntimeException("A single worker should have 1 SystemBolt instance.");
    }
    _prepareWasCalled = true;

    int bucketSize = RT.intCast(stormConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));

    final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();

    context.registerMetric("uptimeSecs", new IMetric() {
        @Override
        public Object getValueAndReset() {
            return jvmRT.getUptime() / 1000.0;
        }
    }, bucketSize);

    context.registerMetric("startTimeSecs", new IMetric() {
        @Override
        public Object getValueAndReset() {
            return jvmRT.getStartTime() / 1000.0;
        }
    }, bucketSize);

    context.registerMetric("newWorkerEvent", new IMetric() {
        boolean doEvent = true;

        @Override
        public Object getValueAndReset() {
            if (doEvent) {
                doEvent = false;
                return 1;
            } else
                return 0;
        }
    }, bucketSize);

    final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();

    context.registerMetric("memory/heap", new MemoryUsageMetric(new AFn() {
        public Object invoke() {
            return jvmMemRT.getHeapMemoryUsage();
        }
    }), bucketSize);
    context.registerMetric("memory/nonHeap", new MemoryUsageMetric(new AFn() {
        public Object invoke() {
            return jvmMemRT.getNonHeapMemoryUsage();
        }
    }), bucketSize);

    for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) {
        context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""), new GarbageCollectorMetric(b), bucketSize);
    }
}
 
Example 10
Source File: PythonShellMetricsBolt.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    super.prepare(stormConf, context, collector);

    CountShellMetric cMetric = new CountShellMetric();
    context.registerMetric("my-custom-shell-metric", cMetric, 5);
}