Ejemplo n.º 1
0
  private void printClusterBaseInfo(final DefaultMQAdminExt defaultMQAdminExt)
      throws RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException,
          InterruptedException, MQBrokerException {

    ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();

    System.out.printf(
        "%-16s  %-32s  %-4s  %-22s %-22s %11s %11s\n", //
        "#Cluster Name", //
        "#Broker Name", //
        "#BID", //
        "#Addr", //
        "#Version", //
        "#InTPS", //
        "#OutTPS" //
        );

    Iterator<Map.Entry<String, Set<String>>> itCluster =
        clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator();
    while (itCluster.hasNext()) {
      Map.Entry<String, Set<String>> next = itCluster.next();
      String clusterName = next.getKey();
      TreeSet<String> brokerNameSet = new TreeSet<String>();
      brokerNameSet.addAll(next.getValue());

      for (String brokerName : brokerNameSet) {
        BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
        if (brokerData != null) {

          Iterator<Map.Entry<Long, String>> itAddr =
              brokerData.getBrokerAddrs().entrySet().iterator();
          while (itAddr.hasNext()) {
            Map.Entry<Long, String> next1 = itAddr.next();
            double in = 0;
            double out = 0;
            String version = "";

            try {
              KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(next1.getValue());
              String putTps = kvTable.getTable().get("putTps");
              String getTransferedTps = kvTable.getTable().get("getTransferedTps");
              version = kvTable.getTable().get("brokerVersionDesc");
              {
                String[] tpss = putTps.split(" ");
                if (tpss != null && tpss.length > 0) {
                  in = Double.parseDouble(tpss[0]);
                }
              }

              {
                String[] tpss = getTransferedTps.split(" ");
                if (tpss != null && tpss.length > 0) {
                  out = Double.parseDouble(tpss[0]);
                }
              }
            } catch (Exception e) {
            }

            System.out.printf(
                "%-16s  %-32s  %-4s  %-22s %-22s %11.2f %11.2f\n", //
                clusterName, //
                brokerName, //
                next1.getKey().longValue(), //
                next1.getValue(), //
                version, //
                in, //
                out //
                );
          }
        }
      }

      if (itCluster.hasNext()) {
        System.out.println("");
      }
    }
  }
Ejemplo n.º 2
0
  private void printClusterMoreStats(final DefaultMQAdminExt defaultMQAdminExt)
      throws RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException,
          InterruptedException, MQBrokerException {

    ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();

    System.out.printf(
        "%-16s  %-32s %14s %14s %14s %14s\n", //
        "#Cluster Name", //
        "#Broker Name", //
        "#InTotalYest", //
        "#OutTotalYest", //
        "#InTotalToday", //
        "#OutTotalToday" //
        );

    Iterator<Map.Entry<String, Set<String>>> itCluster =
        clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator();
    while (itCluster.hasNext()) {
      Map.Entry<String, Set<String>> next = itCluster.next();
      String clusterName = next.getKey();
      TreeSet<String> brokerNameSet = new TreeSet<String>();
      brokerNameSet.addAll(next.getValue());

      for (String brokerName : brokerNameSet) {
        BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
        if (brokerData != null) {

          Iterator<Map.Entry<Long, String>> itAddr =
              brokerData.getBrokerAddrs().entrySet().iterator();
          while (itAddr.hasNext()) {
            Map.Entry<Long, String> next1 = itAddr.next();
            long InTotalYest = 0;
            long OutTotalYest = 0;
            long InTotalToday = 0;
            long OutTotalToday = 0;

            try {
              KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(next1.getValue());
              String msgPutTotalYesterdayMorning =
                  kvTable.getTable().get("msgPutTotalYesterdayMorning");
              String msgPutTotalTodayMorning = kvTable.getTable().get("msgPutTotalTodayMorning");
              String msgPutTotalTodayNow = kvTable.getTable().get("msgPutTotalTodayNow");
              String msgGetTotalYesterdayMorning =
                  kvTable.getTable().get("msgGetTotalYesterdayMorning");
              String msgGetTotalTodayMorning = kvTable.getTable().get("msgGetTotalTodayMorning");
              String msgGetTotalTodayNow = kvTable.getTable().get("msgGetTotalTodayNow");

              InTotalYest =
                  Long.parseLong(msgPutTotalTodayMorning)
                      - Long.parseLong(msgPutTotalYesterdayMorning);
              OutTotalYest =
                  Long.parseLong(msgGetTotalTodayMorning)
                      - Long.parseLong(msgGetTotalYesterdayMorning);

              InTotalToday =
                  Long.parseLong(msgPutTotalTodayNow) - Long.parseLong(msgPutTotalTodayMorning);
              OutTotalToday =
                  Long.parseLong(msgGetTotalTodayNow) - Long.parseLong(msgGetTotalTodayMorning);

            } catch (Exception e) {
            }

            System.out.printf(
                "%-16s  %-32s %14d %14d %14d %14d\n", //
                clusterName, //
                brokerName, //
                InTotalYest, //
                OutTotalYest, //
                InTotalToday, //
                OutTotalToday //
                );
          }
        }
      }

      if (itCluster.hasNext()) {
        System.out.println("");
      }
    }
  }