Search in sources :

Example 6 with DBHeartbeat

use of com.actiontech.dble.backend.heartbeat.DBHeartbeat in project dble by actiontech.

the class ShowHeartbeatDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    String ip = "";
    int port = 0;
    DBHeartbeat hb = null;
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            if (name.equals(ds.getName())) {
                hb = ds.getHeartbeat();
                ip = ds.getConfig().getIp();
                port = ds.getConfig().getPort();
                break;
            }
        }
    }
    if (hb != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Queue<HeartbeatRecorder.Record> heartbeatRecorders = hb.getRecorder().getRecordsAll();
        for (HeartbeatRecorder.Record record : heartbeatRecorders) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, charset));
            row.add(StringUtil.encode(ip, charset));
            row.add(IntegerUtil.toBytes(port));
            long time = record.getTime();
            String timeStr = sdf.format(new Date(time));
            row.add(StringUtil.encode(timeStr, charset));
            row.add(LongUtil.toBytes(record.getValue()));
            list.add(row);
        }
    } else {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        list.add(row);
    }
    return list;
}
Also used : DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) HeartbeatRecorder(com.actiontech.dble.statistic.HeartbeatRecorder) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)6 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)5 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)5 ServerConfig (com.actiontech.dble.config.ServerConfig)5 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)5 LinkedList (java.util.LinkedList)4 DataSourceSyncRecorder (com.actiontech.dble.statistic.DataSourceSyncRecorder)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Record (com.actiontech.dble.statistic.DataSourceSyncRecorder.Record)1 HeartbeatRecorder (com.actiontech.dble.statistic.HeartbeatRecorder)1 Date (java.util.Date)1