- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 49957 个
- 通用积分
- 79.5487
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
|
- package com.learningstorm.monitoring;
- import java.util.Iterator;
- import java.util.Map;
- import backtype.storm.generated.ExecutorSpecificStats;
- import backtype.storm.generated.ExecutorStats;
- import backtype.storm.generated.ExecutorSummary;
- import backtype.storm.generated.Nimbus.Client;
- import backtype.storm.generated.SpoutStats;
- import backtype.storm.generated.TopologyInfo;
- public class SpoutStatistics {
- private static final String DEFAULT = "default";
- private static final String ALL_TIME = ":all-time";
- public void printSpoutStatistics(String topologyId) {
- try {
- ThriftClient thriftClient = new ThriftClient();
- // Get the nimbus thrift client
- Client client = thriftClient.getClient();
- // Get the information of given topology
- TopologyInfo topologyInfo = client.getTopologyInfo(topologyId);
- Iterator<ExecutorSummary> executorSummaryIterator = topologyInfo
- .get_executors_iterator();
- while (executorSummaryIterator.hasNext()) {
- ExecutorSummary executorSummary = executorSummaryIterator.next();
- ExecutorStats executorStats = executorSummary.get_stats();
- if(executorStats !=null) {
- ExecutorSpecificStats executorSpecificStats = executorStats.get_specific();
- String componentId = executorSummary.get_component_id();
- //
- if (executorSpecificStats.is_set_spout()) {
- SpoutStats spoutStats = executorSpecificStats.get_spout();
- System.out.println("*************************************");
- System.out.println("Component ID of Spout:- " + componentId);
- System.out.println("Transferred:- "
- + getAllTimeStat(executorStats.get_transferred(),ALL_TIME));
- System.out.println("Total tuples emitted:- "
- + getAllTimeStat(executorStats.get_emitted(), ALL_TIME));
- System.out.println("Acked: "
- + getAllTimeStat(spoutStats.get_acked(),
- ALL_TIME));
- System.out.println("Failed: "
- + getAllTimeStat(spoutStats.get_failed(),
- ALL_TIME));
- System.out.println("*************************************");
- }
- }
- }
- }catch (Exception exception) {
- throw new RuntimeException("Error occurred while fetching the spout information : "+exception);
- }
- }
- private static Long getAllTimeStat(Map<String, Map<String, Long>> map,
- String statName) {
- if (map != null) {
- Long statValue = null;
- Map<String, Long> tempMap = map.get(statName);
- statValue = tempMap.get(DEFAULT);
- return statValue;
- }
- return 0L;
- }
-
- public static void main(String[] args) {
- new SpoutStatistics().printSpoutStatistics("LearningStormClusterTopology-1-1393847956");
- }
- }
复制代码
|
|