Search in sources :

Example 1 with BrokerStatsItem

use of org.apache.rocketmq.common.protocol.body.BrokerStatsItem in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AdminBrokerProcessor method ViewBrokerStatsData.

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();
    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;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ViewBrokerStatsDataRequestHeader(org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader) BrokerStatsItem(org.apache.rocketmq.common.protocol.body.BrokerStatsItem) BrokerStatsItem(org.apache.rocketmq.common.protocol.body.BrokerStatsItem) StatsItem(org.apache.rocketmq.common.stats.StatsItem) DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData) StatsSnapshot(org.apache.rocketmq.common.stats.StatsSnapshot)

Example 2 with BrokerStatsItem

use of org.apache.rocketmq.common.protocol.body.BrokerStatsItem in project rocketmq by apache.

the class AdminBrokerProcessor method ViewBrokerStatsData.

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();
    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;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ViewBrokerStatsDataRequestHeader(org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader) BrokerStatsItem(org.apache.rocketmq.common.protocol.body.BrokerStatsItem) BrokerStatsItem(org.apache.rocketmq.common.protocol.body.BrokerStatsItem) StatsItem(org.apache.rocketmq.common.stats.StatsItem) DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData) StatsSnapshot(org.apache.rocketmq.common.stats.StatsSnapshot)

Aggregations

BrokerStatsData (org.apache.rocketmq.common.protocol.body.BrokerStatsData)2 BrokerStatsItem (org.apache.rocketmq.common.protocol.body.BrokerStatsItem)2 ViewBrokerStatsDataRequestHeader (org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader)2 StatsItem (org.apache.rocketmq.common.stats.StatsItem)2 StatsSnapshot (org.apache.rocketmq.common.stats.StatsSnapshot)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2 DefaultMessageStore (org.apache.rocketmq.store.DefaultMessageStore)2