Search in sources :

Example 1 with Record

use of io.mycat.statistic.DataSourceSyncRecorder.Record in project Mycat-Server by MyCATApache.

the class ShowDatasourceSynDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.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.getAsynRecorder();
            Map<String, String> states = record.getRecords();
            if (name.equals(ds.getName())) {
                List<Record> data = record.getAsynRecords();
                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.valueOf(states.get("Master_Port"))));
                    row.add(StringUtil.encode(states.get("Master_Use"), charset));
                    //DateFormat非线程安全
                    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(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) DataSourceSyncRecorder(io.mycat.statistic.DataSourceSyncRecorder) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList) Date(java.util.Date) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) Record(io.mycat.statistic.DataSourceSyncRecorder.Record) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)1 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)1 MycatConfig (io.mycat.config.MycatConfig)1 RowDataPacket (io.mycat.net.mysql.RowDataPacket)1 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)1 Record (io.mycat.statistic.DataSourceSyncRecorder.Record)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1