Search in sources :

Example 1 with SQLRecord

use of com.actiontech.dble.statistic.SQLRecord in project dble by actiontech.

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.getPacketId();
    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().getResults());
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        }
        if (isClear) {
            userStat.clearSqlSlow();
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) UserStat(com.actiontech.dble.statistic.stat.UserStat) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) SQLRecord(com.actiontech.dble.statistic.SQLRecord) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 2 with SQLRecord

use of com.actiontech.dble.statistic.SQLRecord in project dble by actiontech.

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 resultSetSize) {
    // -----------------------------------------------------
    int invoking = runningCount.incrementAndGet();
    for (; ; ) {
        int max = concurrentMax.get();
        if (invoking > max) {
            if (concurrentMax.compareAndSet(max, invoking)) {
                break;
            }
        } else {
            break;
        }
    }
    // -----------------------------------------------------
    // slow sql
    long executeTime = endTime - startTime;
    if (executeTime >= sqlSlowTime) {
        SQLRecord record = new SQLRecord();
        record.setExecuteTime(executeTime);
        record.setStatement(sql);
        record.setStartTime(startTime);
        this.sqlRecorder.add(record);
    }
    // sqlRwStat
    this.sqlRwStat.setConcurrentMax(concurrentMax.get());
    this.sqlRwStat.add(sqlType, sql, executeTime, netInBytes, netOutBytes, startTime, endTime);
    // sqlLastStatSQL
    this.sqlLastStat.add(sql, executeTime, startTime, endTime);
    // sqlHighStat
    this.sqlHighStat.addSql(sql, executeTime, startTime, endTime);
    // sqlLargeStat large than 10000 rows
    if (sqlType == ServerParse.SELECT && sqlRows > 10000) {
        this.sqlLargeStat.add(sql, sqlRows, executeTime, startTime, endTime);
    }
    // big size sql
    if (resultSetSize >= DbleServer.getInstance().getConfig().getSystem().getMaxResultSet()) {
        this.sqlResultSizeRecorder.addSql(sql, resultSetSize);
    }
    // after
    // -----------------------------------------------------
    runningCount.decrementAndGet();
}
Also used : SQLRecord(com.actiontech.dble.statistic.SQLRecord)

Aggregations

SQLRecord (com.actiontech.dble.statistic.SQLRecord)2 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)1 UserStat (com.actiontech.dble.statistic.stat.UserStat)1 ByteBuffer (java.nio.ByteBuffer)1