說在前面apache
管理請求之查詢broker狀態數據緩存
源碼解析微信
進入到這個方法org.apache.rocketmq.broker.processor.AdminBrokerProcessor#ViewBrokerStatsDatathis
private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx,RemotingCommand request) throws RemotingCommandException {final ViewBrokerStatsDataRequestHeader requestHeader =(ViewBrokerStatsDataRequestHeader) request.decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class);final RemotingCommand response = RemotingCommand.createResponseCommand(null);DefaultMessageStore messageStore = (DefaultMessageStore) this.brokerController.getMessageStore();// 從緩存中獲取broker的狀態數據=》StatsItem statsItem = messageStore.getBrokerStatsManager().getStatsItem(requestHeader.getStatsName(), requestHeader.getStatsKey());if (null == statsItem) {response.setCode(ResponseCode.SYSTEM_ERROR);response.setRemark(String.format("The stats <%s> <%s> not exist", requestHeader.getStatsName(), requestHeader.getStatsKey()));return response;}BrokerStatsData brokerStatsData = new BrokerStatsData();{BrokerStatsItem it = new BrokerStatsItem();StatsSnapshot ss = statsItem.getStatsDataInMinute();it.setSum(ss.getSum());it.setTps(ss.getTps());it.setAvgpt(ss.getAvgpt());brokerStatsData.setStatsMinute(it);}{BrokerStatsItem it = new BrokerStatsItem();StatsSnapshot ss = statsItem.getStatsDataInHour();it.setSum(ss.getSum());it.setTps(ss.getTps());it.setAvgpt(ss.getAvgpt());brokerStatsData.setStatsHour(it);}{BrokerStatsItem it = new BrokerStatsItem();StatsSnapshot ss = statsItem.getStatsDataInDay();it.setSum(ss.getSum());it.setTps(ss.getTps());it.setAvgpt(ss.getAvgpt());brokerStatsData.setStatsDay(it);}response.setBody(brokerStatsData.encode());response.setCode(ResponseCode.SUCCESS);response.setRemark(null);return response;}
進入這個方法,從緩存中獲取broker的狀態數據,org.apache.rocketmq.store.stats.BrokerStatsManager#getStatsItemcode
public StatsItem getStatsItem(final String statsName, final String statsKey) {try {return this.statsTable.get(statsName).getStatsItem(statsKey);} catch (Exception e) {}return null;}
往上返回到這個方法org.apache.rocketmq.broker.processor.AdminBrokerProcessor#ViewBrokerStatsData結束。orm
說在最後blog
本次解析僅表明我的觀點,僅供參考。get
加入技術微信羣源碼
釘釘技術羣it