Search in sources :

Example 6 with UserStat

use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.

the class ShowSQLSlow 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<SQLRecord> keyList = userStat.getSqlRecorder().getRecords();
        for (SQLRecord key : keyList) {
            if (key != null) {
                RowDataPacket row = getRow(user, key, c.getCharset());
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        }
        if (isClear) {
            //读取慢SQL后,清理
            userStat.getSqlRecorder().clear();
        }
    }
    // write last eof
    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) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) SQLRecord(io.mycat.statistic.SQLRecord) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 7 with UserStat

use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.

the class ShowSQL 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<UserSqlLastStat.SqlLast> sqls = userStat.getSqlLastStat().getSqls();
        int i = 1;
        for (UserSqlLastStat.SqlLast sqlLast : sqls) {
            if (sqlLast != null) {
                RowDataPacket row = getRow(user, sqlLast, i, c.getCharset());
                row.packetId = ++packetId;
                i++;
                buffer = row.write(buffer, c, true);
            }
        }
        //读取SQL监控后清理
        if (isClear) {
            userStat.getSqlLastStat().clear();
        }
    }
    // write last eof
    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) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) UserSqlLastStat(io.mycat.statistic.stat.UserSqlLastStat) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 8 with UserStat

use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.

the class ReloadUserStat method execute.

public static void execute(ManagerConnection c) {
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        userStat.reset();
    }
    StringBuilder s = new StringBuilder();
    s.append(c).append("Reset show @@sql  @@sql.sum  @@sql.slow success by manager");
    logger.warn(s.toString());
    OkPacket ok = new OkPacket();
    ok.packetId = 1;
    ok.affectedRows = 1;
    ok.serverStatus = 2;
    ok.message = "Reset show @@sql  @@sql.sum @@sql.slow success".getBytes();
    ok.write(c);
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket) UserStat(io.mycat.statistic.stat.UserStat)

Example 9 with UserStat

use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.

the class ShowSQLLarge 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<UserSqlLargeStat.SqlLarge> sqls = userStat.getSqlLargeRowStat().getSqls();
        for (UserSqlLargeStat.SqlLarge sql : sqls) {
            if (sql != null) {
                RowDataPacket row = getRow(user, sql, c.getCharset());
                row.packetId = ++packetId;
                buffer = row.write(buffer, c, true);
            }
        }
        if (isClear) {
            //读取大结果集SQL后,清理
            userStat.getSqlLargeRowStat().clear();
        }
    }
    // write last eof
    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) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket) UserSqlLargeStat(io.mycat.statistic.stat.UserSqlLargeStat)

Example 10 with UserStat

use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.

the class ShowSQLSumUser 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;
    int i = 0;
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        i++;
        //getRow(sqlStat,sql, c.getCharset());
        RowDataPacket row = getRow(userStat, i, c.getCharset());
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
        if (isClear) {
            userStat.clearRwStat();
        }
    }
    // write last eof
    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) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

UserStat (io.mycat.statistic.stat.UserStat)10 EOFPacket (io.mycat.net.mysql.EOFPacket)6 FieldPacket (io.mycat.net.mysql.FieldPacket)6 RowDataPacket (io.mycat.net.mysql.RowDataPacket)6 ByteBuffer (java.nio.ByteBuffer)6 OkPacket (io.mycat.net.mysql.OkPacket)2 BufferPool (io.mycat.buffer.BufferPool)1 DirectByteBufferPool (io.mycat.buffer.DirectByteBufferPool)1 SQLRecord (io.mycat.statistic.SQLRecord)1 SqlFrequency (io.mycat.statistic.stat.SqlFrequency)1 SqlResultSet (io.mycat.statistic.stat.SqlResultSet)1 SqlResultSizeRecorder (io.mycat.statistic.stat.SqlResultSizeRecorder)1 UserSqlLargeStat (io.mycat.statistic.stat.UserSqlLargeStat)1 UserSqlLastStat (io.mycat.statistic.stat.UserSqlLastStat)1