Search in sources :

Example 1 with Record

use of com.actiontech.dble.statistic.DataSourceSyncRecorder.Record in project dble by actiontech.

the class ShowDatasourceSynDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsyncRecorder();
            Map<String, String> states = record.getRecords();
            if (name.equals(ds.getName())) {
                List<Record> data = record.getAsyncRecords();
                for (Record r : data) {
                    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
                    row.add(StringUtil.encode(ds.getName(), charset));
                    row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                    row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                    row.add(StringUtil.encode(states.get("Master_Host"), charset));
                    row.add(LongUtil.toBytes(Long.parseLong(states.get("Master_Port"))));
                    row.add(StringUtil.encode(states.get("Master_User"), charset));
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String time = sdf.format(new Date(r.getTime()));
                    row.add(StringUtil.encode(time, charset));
                    row.add(LongUtil.toBytes((Long) r.getValue()));
                    list.add(row);
                }
                break;
            }
        }
    }
    return list;
}
Also used : DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) DataSourceSyncRecorder(com.actiontech.dble.statistic.DataSourceSyncRecorder) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList) Date(java.util.Date) ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) Record(com.actiontech.dble.statistic.DataSourceSyncRecorder.Record) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

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