Search in sources :

Example 6 with UserStat

use of com.actiontech.dble.statistic.stat.UserStat in project dble by actiontech.

the class DbleServer method recycleSqlStat.

// clean up the old data in SqlStat
private Runnable recycleSqlStat() {
    return new Runnable() {

        @Override
        public void run() {
            Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
            for (UserStat userStat : statMap.values()) {
                userStat.getSqlLastStat().recycle();
                userStat.getSqlRecorder().recycle();
                userStat.getSqlHigh().recycle();
                userStat.getSqlLargeRowStat().recycle();
            }
        }
    };
}
Also used : UserStat(com.actiontech.dble.statistic.stat.UserStat)

Example 7 with UserStat

use of com.actiontech.dble.statistic.stat.UserStat in project dble by actiontech.

the class ReloadSqlSlowTime method execute.

public static void execute(ManagerConnection c, long time) {
    Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
    for (UserStat userStat : statMap.values()) {
        userStat.setSlowTime(time);
    }
    LOGGER.info(String.valueOf(c) + "Reset show  @@sql.slow=" + time + " time success by manager");
    OkPacket ok = new OkPacket();
    ok.setPacketId(1);
    ok.setAffectedRows(1);
    ok.setServerStatus(2);
    ok.setMessage("Reset show  @@sql.slow time success".getBytes());
    ok.write(c);
}
Also used : OkPacket(com.actiontech.dble.net.mysql.OkPacket) UserStat(com.actiontech.dble.statistic.stat.UserStat)

Example 8 with UserStat

use of com.actiontech.dble.statistic.stat.UserStat in project dble by actiontech.

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();
    }
    LOGGER.info(String.valueOf(c) + "Reset show @@sql  @@sql.sum  @@sql.slow  @@sql.high  @@sql.large  @@sql.resultset success by manager");
    OkPacket ok = new OkPacket();
    ok.setPacketId(1);
    ok.setAffectedRows(1);
    ok.setServerStatus(2);
    ok.setMessage("Reset show @@sql  @@sql.sum @@sql.slow  @@sql.high  @@sql.large  @@sql.resultset  success".getBytes());
    ok.write(c);
}
Also used : OkPacket(com.actiontech.dble.net.mysql.OkPacket) UserStat(com.actiontech.dble.statistic.stat.UserStat)

Example 9 with UserStat

use of com.actiontech.dble.statistic.stat.UserStat 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 10 with UserStat

use of com.actiontech.dble.statistic.stat.UserStat in project dble by actiontech.

the class DbleServer method resultSetMapClear.

/**
 * clean up the data in UserStatAnalyzer
 */
private Runnable resultSetMapClear() {
    return new Runnable() {

        @Override
        public void run() {
            try {
                BufferPool pool = getBufferPool();
                long bufferSize = pool.size();
                long bufferCapacity = pool.capacity();
                long bufferUsagePercent = (bufferCapacity - bufferSize) * 100 / bufferCapacity;
                if (bufferUsagePercent < DbleServer.getInstance().getConfig().getSystem().getBufferUsagePercent()) {
                    Map<String, UserStat> map = UserStatAnalyzer.getInstance().getUserStatMap();
                    Set<String> userSet = DbleServer.getInstance().getConfig().getUsers().keySet();
                    for (String user : userSet) {
                        UserStat userStat = map.get(user);
                        if (userStat != null) {
                            SqlResultSizeRecorder recorder = userStat.getSqlResultSizeRecorder();
                            recorder.clearSqlResultSet();
                        }
                    }
                }
            } catch (Exception e) {
                LOGGER.info("resultSetMapClear err " + e);
            }
        }
    };
}
Also used : DirectByteBufferPool(com.actiontech.dble.buffer.DirectByteBufferPool) BufferPool(com.actiontech.dble.buffer.BufferPool) UserStat(com.actiontech.dble.statistic.stat.UserStat) SqlResultSizeRecorder(com.actiontech.dble.statistic.stat.SqlResultSizeRecorder)

Aggregations

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