Search in sources :

Example 1 with SQLRecord

use of io.mycat.statistic.SQLRecord 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 2 with SQLRecord

use of io.mycat.statistic.SQLRecord in project Mycat_plus by coderczp.

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 3 with SQLRecord

use of io.mycat.statistic.SQLRecord in project Mycat_plus by coderczp.

the class UserStat method update.

/**
 * 更新状态
 *
 * @param sqlType
 * @param sql
 * @param startTime
 */
public void update(int sqlType, String sql, long sqlRows, long netInBytes, long netOutBytes, long startTime, long endTime, int rseultSetSize) {
    // before 计算最大并发数
    // -----------------------------------------------------
    int invoking = runningCount.incrementAndGet();
    for (; ; ) {
        int max = concurrentMax.get();
        if (invoking > max) {
            if (concurrentMax.compareAndSet(max, invoking)) {
                break;
            }
        } else {
            break;
        }
    }
    // -----------------------------------------------------
    // this.lock.writeLock().lock();
    // try {
    // 慢查询记录
    long executeTime = endTime - startTime;
    if (executeTime >= SQL_SLOW_TIME) {
        SQLRecord record = new SQLRecord();
        record.executeTime = executeTime;
        record.statement = sql;
        record.startTime = startTime;
        this.sqlRecorder.add(record);
    }
    // 执行状态记录
    this.sqlRwStat.setConcurrentMax(concurrentMax.get());
    this.sqlRwStat.add(sqlType, sql, executeTime, netInBytes, netOutBytes, startTime, endTime);
    // 记录最新执行的SQL
    this.sqlLastStat.add(sql, executeTime, startTime, endTime);
    // 记录高频SQL
    this.sqlHighStat.addSql(sql, executeTime, startTime, endTime);
    // 记录SQL Select 返回超过 10000 行的 大结果集
    if (sqlType == ServerParse.SELECT && sqlRows > 10000) {
        this.sqlLargeStat.add(sql, sqlRows, executeTime, startTime, endTime);
    }
    // 记录超过阈值的大结果集sql
    if (rseultSetSize >= MycatServer.getInstance().getConfig().getSystem().getMaxResultSet()) {
        this.sqlResultSizeRecorder.addSql(sql, rseultSetSize);
    }
    // } finally {
    // this.lock.writeLock().unlock();
    // }
    // after
    // -----------------------------------------------------
    runningCount.decrementAndGet();
}
Also used : SQLRecord(io.mycat.statistic.SQLRecord)

Example 4 with SQLRecord

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

the class UserStat method update.

/**
 * 更新状态
 *
 * @param sqlType
 * @param sql
 * @param startTime
 */
public void update(int sqlType, String sql, long sqlRows, long netInBytes, long netOutBytes, long startTime, long endTime, int rseultSetSize) {
    // before 计算最大并发数
    // -----------------------------------------------------
    int invoking = runningCount.incrementAndGet();
    for (; ; ) {
        int max = concurrentMax.get();
        if (invoking > max) {
            if (concurrentMax.compareAndSet(max, invoking)) {
                break;
            }
        } else {
            break;
        }
    }
    // -----------------------------------------------------
    // this.lock.writeLock().lock();
    // try {
    // 慢查询记录
    long executeTime = endTime - startTime;
    if (executeTime >= SQL_SLOW_TIME) {
        SQLRecord record = new SQLRecord();
        record.executeTime = executeTime;
        record.statement = sql;
        record.startTime = startTime;
        this.sqlRecorder.add(record);
    }
    // 执行状态记录
    this.sqlRwStat.setConcurrentMax(concurrentMax.get());
    this.sqlRwStat.add(sqlType, sql, executeTime, netInBytes, netOutBytes, startTime, endTime);
    // 记录最新执行的SQL
    this.sqlLastStat.add(sql, executeTime, startTime, endTime);
    // 记录高频SQL
    this.sqlHighStat.addSql(sql, executeTime, startTime, endTime);
    // 记录SQL Select 返回超过 10000 行的 大结果集
    if (sqlType == ServerParse.SELECT && sqlRows > 10000) {
        this.sqlLargeStat.add(sql, sqlRows, executeTime, startTime, endTime);
    }
    // 记录超过阈值的大结果集sql
    if (rseultSetSize >= MycatServer.getInstance().getConfig().getSystem().getMaxResultSet()) {
        this.sqlResultSizeRecorder.addSql(sql, rseultSetSize);
    }
    // } finally {
    // this.lock.writeLock().unlock();
    // }
    // after
    // -----------------------------------------------------
    runningCount.decrementAndGet();
}
Also used : SQLRecord(io.mycat.statistic.SQLRecord)

Aggregations

SQLRecord (io.mycat.statistic.SQLRecord)4 EOFPacket (io.mycat.net.mysql.EOFPacket)2 FieldPacket (io.mycat.net.mysql.FieldPacket)2 RowDataPacket (io.mycat.net.mysql.RowDataPacket)2 UserStat (io.mycat.statistic.stat.UserStat)2 ByteBuffer (java.nio.ByteBuffer)2