Search in sources :

Example 31 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowSQLHigh method execute.

public static void execute(ManagerConnection c, boolean isClear) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        String user = userStat.getUser();
        List<SqlFrequency> list = userStat.getSqlHigh().getSqlFrequency(isClear);
        if (list != null) {
            int i = 1;
            for (SqlFrequency sqlFrequency : list) {
                if (sqlFrequency != null) {
                    RowDataPacket row = getRow(i, user, sqlFrequency.getSql(), sqlFrequency.getCount(), sqlFrequency.getAvgTime(), sqlFrequency.getMaxTime(), sqlFrequency.getMinTime(), sqlFrequency.getExecuteTime(), sqlFrequency.getLastTime(), c.getCharset());
                    row.packetId = ++packetId;
                    buffer = row.write(buffer, c, true);
                    i++;
                }
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : SqlFrequency(io.mycat.statistic.stat.SqlFrequency) RowDataPacket(io.mycat.net.mysql.RowDataPacket) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 32 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowSQLSumUser method getRow.

private static RowDataPacket getRow(UserStat userStat, long idx, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(idx));
    if (userStat == null) {
        row.add(StringUtil.encode(("not fond"), charset));
        return row;
    }
    String user = userStat.getUser();
    UserSqlRWStat rwStat = userStat.getRWStat();
    long R = rwStat.getRCount();
    long W = rwStat.getWCount();
    String __R = decimalFormat.format(1.0D * R / (R + W));
    int MAX = rwStat.getConcurrentMax();
    row.add(StringUtil.encode(user, charset));
    row.add(LongUtil.toBytes(R));
    row.add(LongUtil.toBytes(W));
    row.add(StringUtil.encode(String.valueOf(__R), charset));
    row.add(StringUtil.encode(String.valueOf(MAX), charset));
    row.add(LongUtil.toBytes(rwStat.getNetInBytes()));
    row.add(LongUtil.toBytes(rwStat.getNetOutBytes()));
    row.add(StringUtil.encode(rwStat.getExecuteHistogram().toString(), charset));
    row.add(StringUtil.encode(rwStat.getTimeHistogram().toString(), charset));
    row.add(LongUtil.toBytes(rwStat.getLastExecuteTime()));
    return row;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) UserSqlRWStat(io.mycat.statistic.stat.UserSqlRWStat)

Example 33 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowDataNode method getRow.

private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(node.getName(), charset));
    row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
    PhysicalDBPool pool = node.getDbPool();
    PhysicalDatasource ds = pool.getSource();
    if (ds != null) {
        int active = ds.getActiveCountForSchema(node.getDatabase());
        int idle = ds.getIdleCountForSchema(node.getDatabase());
        row.add(IntegerUtil.toBytes(pool.getActivedIndex()));
        row.add(StringUtil.encode(ds.getConfig().getDbType(), charset));
        row.add(IntegerUtil.toBytes(active));
        row.add(IntegerUtil.toBytes(idle));
        row.add(IntegerUtil.toBytes(ds.getSize()));
    } else {
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
    }
    row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(LongUtil.toBytes(0));
    long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
    row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
    return row;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) RowDataPacket(io.mycat.net.mysql.RowDataPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool)

Example 34 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowBackend method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c, true);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    buffer = eof.write(buffer, c, true);
    byte packetId = eof.packetId;
    String charset = c.getCharset();
    for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            if (bc != null) {
                RowDataPacket row = getRow(bc, charset);
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        }
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : BackendConnection(io.mycat.backend.BackendConnection) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 35 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.

the class ShowCollation method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    RowDataPacket row = getRow(c.getCharset());
    row.packetId = ++packetId;
    buffer = row.write(buffer, c, true);
    // write lastEof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

RowDataPacket (io.mycat.net.mysql.RowDataPacket)269 FieldPacket (io.mycat.net.mysql.FieldPacket)143 ByteBuffer (java.nio.ByteBuffer)140 EOFPacket (io.mycat.net.mysql.EOFPacket)137 MycatConfig (io.mycat.config.MycatConfig)20 LinkedList (java.util.LinkedList)16 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)14 NIOProcessor (io.mycat.net.NIOProcessor)14 SchemaConfig (io.mycat.config.model.SchemaConfig)13 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)13 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)12 UserStat (io.mycat.statistic.stat.UserStat)12 IOException (java.io.IOException)12 Map (java.util.Map)12 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)10 ServerConnection (io.mycat.server.ServerConnection)10 BinaryRowDataPacket (io.mycat.net.mysql.BinaryRowDataPacket)8 File (java.io.File)8 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)6 BufferedReader (java.io.BufferedReader)6