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

The following are Jave code examples for showing how to use registerMetric() of the backtype.storm.task.TopologyContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: rb-bi   File: TridentKafkaEmitter.java   Source Code and License Vote up 5 votes
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 2
Project: storm-scheduler   File: SchedulingMetricsCollectionHook.java   Source Code and License Vote up 4 votes
@Override
public void prepare(Map conf, final TopologyContext context) {
    if (context.getThisTaskId() < 0) {
        LOG.debug("Skipping installation of metrics hook for negative task id {}", context.getThisTaskId());
    } else {
        int intervalSecs;

        LOG.info("Initializing metrics hook for task {}", context.getThisTaskId());

        this.sendgraphRef = new AtomicReference<>();

        intervalSecs = getConfiguredSchedulingIntervalSecs(conf);

        /*
        * We register one metric for each task. The full send graph will then be built up in the metric
        * consumer.
        */
        context.registerMetric(METRIC_EMITTED_MESSAGES, new IMetric() {
            @Override
            public Object getValueAndReset() {
                Map<Integer, AtomicLong> currentValue;

                // don't reset sendgraph! todo: make this configurable
                // currentValue = SchedulingMetricsCollectionHook.this.sendgraphRef.getAndSet(createEmptySendgraphMap());
                currentValue = SchedulingMetricsCollectionHook.this.sendgraphRef.get();

                LOG.trace("Reset values for task {} and returning: {}", context.getThisTaskId(), currentValue.toString());

                return currentValue;
            }

        }, intervalSecs); // call every n seconds

        // put an empty send graph object.
        this.sendgraphRef.compareAndSet(null, createEmptySendgraphMap());

        // put a zero weight for the task at hand, so we have a complete send graph in the metrics. Without this
        // step, tasks that don't send or receive anything (for example the metrics-consumers) would not be
        // contained in the sendgraph. todo: change the schedule format to contain task=>partition assignements, so
        // we could do away with this workaround
        this.sendgraphRef.get().get(context.getThisTaskId()).set(0);
    }
}