Search in sources :

Example 1 with CobarHeartbeat

use of com.alibaba.cobar.heartbeat.CobarHeartbeat in project cobar by alibaba.

the class ShowHeartbeat method getRows.

private static List<RowDataPacket> getRows() {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    CobarConfig conf = CobarServer.getInstance().getConfig();
    // cobar nodes
    Map<String, CobarNode> cobarNodes = conf.getCluster().getNodes();
    List<String> cobarNodeKeys = new ArrayList<String>(cobarNodes.size());
    cobarNodeKeys.addAll(cobarNodes.keySet());
    Collections.sort(cobarNodeKeys);
    for (String key : cobarNodeKeys) {
        CobarNode node = cobarNodes.get(key);
        if (node != null) {
            CobarHeartbeat hb = node.getHeartbeat();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(node.getName().getBytes());
            row.add("COBAR".getBytes());
            row.add(node.getConfig().getHost().getBytes());
            row.add(IntegerUtil.toBytes(node.getConfig().getPort()));
            row.add(IntegerUtil.toBytes(hb.getStatus()));
            row.add(IntegerUtil.toBytes(hb.getErrorCount()));
            row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
            row.add(LongUtil.toBytes(hb.getTimeout()));
            row.add(hb.getRecorder().get().getBytes());
            String at = hb.lastActiveTime();
            row.add(at == null ? null : at.getBytes());
            row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
            list.add(row);
        }
    }
    // data nodes
    Map<String, MySQLDataNode> dataNodes = conf.getDataNodes();
    List<String> dataNodeKeys = new ArrayList<String>(dataNodes.size());
    dataNodeKeys.addAll(dataNodes.keySet());
    Collections.sort(dataNodeKeys, new Comparators<String>());
    for (String key : dataNodeKeys) {
        MySQLDataNode node = dataNodes.get(key);
        if (node != null) {
            MySQLHeartbeat hb = node.getHeartbeat();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(node.getName().getBytes());
            row.add("MYSQL".getBytes());
            if (hb != null) {
                row.add(hb.getSource().getConfig().getHost().getBytes());
                row.add(IntegerUtil.toBytes(hb.getSource().getConfig().getPort()));
                row.add(IntegerUtil.toBytes(hb.getStatus()));
                row.add(IntegerUtil.toBytes(hb.getErrorCount()));
                row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
                row.add(LongUtil.toBytes(hb.getTimeout()));
                row.add(hb.getRecorder().get().getBytes());
                String lat = hb.getLastActiveTime();
                row.add(lat == null ? null : lat.getBytes());
                row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
            } else {
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
            }
            list.add(row);
        }
    }
    return list;
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList) MySQLHeartbeat(com.alibaba.cobar.heartbeat.MySQLHeartbeat) CobarConfig(com.alibaba.cobar.CobarConfig) LinkedList(java.util.LinkedList) CobarHeartbeat(com.alibaba.cobar.heartbeat.CobarHeartbeat) CobarNode(com.alibaba.cobar.CobarNode)

Example 2 with CobarHeartbeat

use of com.alibaba.cobar.heartbeat.CobarHeartbeat in project cobar by alibaba.

the class ShowBackend method getRow.

private static RowDataPacket getRow(BackendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(c.getProcessor().getName().getBytes());
    row.add(LongUtil.toBytes(c.getId()));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    row.add(c.isClosed() ? "true".getBytes() : "false".getBytes());
    if (c instanceof CobarDetector) {
        CobarDetector detector = (CobarDetector) c;
        CobarHeartbeat heartbeat = detector.getHeartbeat();
        row.add(detector.isAuthenticated() ? "true".getBytes() : "false".getBytes());
        row.add(detector.isQuit() ? "true".getBytes() : "false".getBytes());
        row.add(heartbeat.isChecking() ? "true".getBytes() : "false".getBytes());
        row.add(heartbeat.isStop() ? "true".getBytes() : "false".getBytes());
        row.add(LongUtil.toBytes(heartbeat.getStatus()));
    } else if (c instanceof MySQLDetector) {
        MySQLDetector detector = (MySQLDetector) c;
        MySQLHeartbeat heartbeat = detector.getHeartbeat();
        row.add(detector.isAuthenticated() ? "true".getBytes() : "false".getBytes());
        row.add(detector.isQuit() ? "true".getBytes() : "false".getBytes());
        row.add(heartbeat.isChecking() ? "true".getBytes() : "false".getBytes());
        row.add(heartbeat.isStop() ? "true".getBytes() : "false".getBytes());
        row.add(LongUtil.toBytes(heartbeat.getStatus()));
    } else {
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
    }
    return row;
}
Also used : CobarHeartbeat(com.alibaba.cobar.heartbeat.CobarHeartbeat) MySQLDetector(com.alibaba.cobar.heartbeat.MySQLDetector) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) MySQLHeartbeat(com.alibaba.cobar.heartbeat.MySQLHeartbeat) CobarDetector(com.alibaba.cobar.heartbeat.CobarDetector)

Aggregations

CobarHeartbeat (com.alibaba.cobar.heartbeat.CobarHeartbeat)2 MySQLHeartbeat (com.alibaba.cobar.heartbeat.MySQLHeartbeat)2 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)2 CobarConfig (com.alibaba.cobar.CobarConfig)1 CobarNode (com.alibaba.cobar.CobarNode)1 CobarDetector (com.alibaba.cobar.heartbeat.CobarDetector)1 MySQLDetector (com.alibaba.cobar.heartbeat.MySQLDetector)1 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1