Search in sources :

Example 1 with KVTable

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

the class BrokerStatusSubCommand method printBrokerRuntimeStats.

public void printBrokerRuntimeStats(final DefaultMQAdminExt defaultMQAdminExt, final String brokerAddr, final boolean printBroker) throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);
    // 为了排序
    TreeMap<String, String> tmp = new TreeMap<String, String>();
    tmp.putAll(kvTable.getTable());
    Iterator<Entry<String, String>> it = tmp.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, String> next = it.next();
        if (printBroker) {
            System.out.printf("%-24s %-32s: %s%n", brokerAddr, next.getKey(), next.getValue());
        } else {
            System.out.printf("%-32s: %s%n", next.getKey(), next.getValue());
        }
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) Entry(java.util.Map.Entry) TreeMap(java.util.TreeMap)

Example 2 with KVTable

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

the class AdminBrokerProcessor method getBrokerRuntimeInfo.

private RemotingCommand getBrokerRuntimeInfo(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    HashMap<String, String> runtimeInfo = this.prepareRuntimeInfo();
    KVTable kvTable = new KVTable();
    kvTable.setTable(runtimeInfo);
    byte[] body = kvTable.encode();
    response.setBody(body);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) KVTable(org.apache.rocketmq.common.protocol.body.KVTable)

Example 3 with KVTable

use of org.apache.rocketmq.common.protocol.body.KVTable in project rocketmq-externals by apache.

the class DashboardCollectTask method collectBroker.

@Scheduled(cron = "0 0/1 * * * ?")
public void collectBroker() {
    if (!rmqConfigure.isEnableDashBoardCollect()) {
        return;
    }
    try {
        Date date = new Date();
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        Set<Map.Entry<String, BrokerData>> clusterEntries = clusterInfo.getBrokerAddrTable().entrySet();
        Map<String, String> addresses = Maps.newHashMap();
        for (Map.Entry<String, BrokerData> clusterEntry : clusterEntries) {
            HashMap<Long, String> addrs = clusterEntry.getValue().getBrokerAddrs();
            Set<Map.Entry<Long, String>> addrsEntries = addrs.entrySet();
            for (Map.Entry<Long, String> addrEntry : addrsEntries) {
                addresses.put(addrEntry.getValue(), clusterEntry.getKey() + ":" + addrEntry.getKey());
            }
        }
        Set<Map.Entry<String, String>> entries = addresses.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            List<String> list = dashboardCollectService.getBrokerMap().get(entry.getValue());
            if (null == list) {
                list = Lists.newArrayList();
            }
            KVTable kvTable = fetchBrokerRuntimeStats(entry.getKey(), 3);
            if (kvTable == null) {
                continue;
            }
            String[] tpsArray = kvTable.getTable().get("getTotalTps").split(" ");
            BigDecimal totalTps = new BigDecimal(0);
            for (String tps : tpsArray) {
                totalTps = totalTps.add(new BigDecimal(tps));
            }
            BigDecimal averageTps = totalTps.divide(new BigDecimal(tpsArray.length), 5, BigDecimal.ROUND_HALF_UP);
            list.add(date.getTime() + "," + averageTps.toString());
            dashboardCollectService.getBrokerMap().put(entry.getValue(), list);
        }
        log.debug("Broker Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getBrokerMap().asMap()));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Date(java.util.Date) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) HashMap(java.util.HashMap) Map(java.util.Map) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 4 with KVTable

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

the class KVConfigManager method getKVListByNamespace.

public byte[] getKVListByNamespace(final String namespace) {
    try {
        this.lock.readLock().lockInterruptibly();
        try {
            HashMap<String, String> kvTable = this.configTable.get(namespace);
            if (null != kvTable) {
                KVTable table = new KVTable();
                table.setTable(kvTable);
                return table.encode();
            }
        } finally {
            this.lock.readLock().unlock();
        }
    } catch (InterruptedException e) {
        log.error("getKVListByNamespace InterruptedException", e);
    }
    return null;
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable)

Example 5 with KVTable

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

the class MQClientAPIImpl method getBrokerRuntimeInfo.

public KVTable getBrokerRuntimeInfo(final String addr, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_RUNTIME_INFO, null);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                return KVTable.decode(response.getBody(), KVTable.class);
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Aggregations

KVTable (org.apache.rocketmq.common.protocol.body.KVTable)24 Map (java.util.Map)8 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)8 Set (java.util.Set)6 TreeSet (java.util.TreeSet)6 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)6 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)6 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Field (java.lang.reflect.Field)4 TreeMap (java.util.TreeMap)4 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)4 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)4 RemotingConnectException (org.apache.rocketmq.remoting.exception.RemotingConnectException)4 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)4 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)4 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 BeforeClass (org.junit.BeforeClass)3