Search in sources :

Example 1 with ViewBrokerStatsDataRequestHeader

use of org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader 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 ViewBrokerStatsDataRequestHeader

use of org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader 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)

Example 3 with ViewBrokerStatsDataRequestHeader

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

the class MQClientAPIImpl method viewBrokerStatsData.

public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey, long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    ViewBrokerStatsDataRequestHeader requestHeader = new ViewBrokerStatsDataRequestHeader();
    requestHeader.setStatsName(statsName);
    requestHeader.setStatsKey(statsKey);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.VIEW_BROKER_STATS_DATA, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                byte[] body = response.getBody();
                if (body != null) {
                    return BrokerStatsData.decode(body, BrokerStatsData.class);
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ViewBrokerStatsDataRequestHeader(org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData)

Example 4 with ViewBrokerStatsDataRequestHeader

use of org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader in project rocketmq by apache.

the class MQClientAPIImpl method viewBrokerStatsData.

public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey, long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    ViewBrokerStatsDataRequestHeader requestHeader = new ViewBrokerStatsDataRequestHeader();
    requestHeader.setStatsName(statsName);
    requestHeader.setStatsKey(statsKey);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.VIEW_BROKER_STATS_DATA, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                byte[] body = response.getBody();
                if (body != null) {
                    return BrokerStatsData.decode(body, BrokerStatsData.class);
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ViewBrokerStatsDataRequestHeader(org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData)

Aggregations

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