使用自定义的IScheduler时,如何将指标从远程Storm worker发送到Graphite服务器?

时间:2019-03-21 10:03:07

标签: apache-storm scheduling graphite graphite-carbon

我很好地收集了从Apache Storm到Graphite的指标。然后,我开发了一个自定义的计划程序,该程序实现了IScheduler接口,现在我无法收集任何指标。

这是我的scheduler

public class SiteAwareScheduler implements IScheduler {
    @Override
    public void prepare(Map conf) {
    }
    @Override
    public void schedule(Topologies topologies, Cluster cluster) {
        ....
    }
}

在storm.yaml文件上:

supervisor.scheduler.meta:
  site: "cluster"
storm.scheduler: "org.sense.storm.scheduler.SiteAwareScheduler"

我正在使用this library收集指标并将其发送到Graphite服务器。

public class MyTopology {
    config.put(YammerFacadeMetric.FACADE_METRIC_TIME_BUCKET_IN_SEC, 30);
    config.put(SimpleGraphiteStormMetricProcessor.GRAPHITE_HOST, "127.0.0.1");
    config.put(SimpleGraphiteStormMetricProcessor.GRAPHITE_PORT, 2003);
    config.put(SimpleGraphiteStormMetricProcessor.REPORT_PERIOD_IN_SEC, 10);
    config.put(Config.TOPOLOGY_NAME, "MqttSensorSumTopology");
    config.registerMetricsConsumer(MetricReporter.class, new MetricReporterConfig(".*", SimpleGraphiteStormMetricProcessor.class.getCanonicalName()), 1);
    ...
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    ...
    topologyBuilder.setBolt(MqttSensors.BOLT_SENSOR_TICKET_SUM.getValue(), new SumSensorValuesWindowBolt(SensorType.COUNTER_TICKETS).withTumblingWindow(Duration.seconds(5)), 1)
.shuffleGrouping(MqttSensors.SPOUT_STATION_01_TICKETS.getValue())
.addConfiguration(TagSite.SITE.getValue(), TagSite.CLUSTER.getValue());
}

public class SumSensorValuesWindowBolt extends BaseWindowedBolt {
    public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
        StormYammerMetricsAdapter.configure(stormConf, context, new MetricsRegistry());
        this.collector = collector;
    }
    public void execute(TupleWindow inputWindow) {
        ...
    }
}

IScheduler的“ prepare”方法没有TopologyContext,所以我不知道在哪里使用新的时间表实例化指标。

有任何提示吗? 谢谢 费利佩

1 个答案:

答案 0 :(得分:0)

我已在此link上安装了Graphite。然后,我在两台计算机上都按照此link中的说明配置了文件storm.yaml。主人和工人。

storm.metrics.reporters:
  # Graphite Reporter
  - class: "org.apache.storm.metrics2.reporters.GraphiteStormReporter"
    daemons:
        - "supervisor"
        - "nimbus"
        - "worker"
    report.period: 60
    report.period.units: "SECONDS"
    graphite.host: "localhost"
    graphite.port: 2003

然后,指标将以我的拓扑MqttSensorSumTopology-1-1553506290的名称显示在Graphite服务器上。 enter image description here