use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.
the class ShowServerLog method handle.
public static void handle(String stmt, ManagerConnection c) {
Map<String, String> condPairMap = getCondPair(stmt);
if (condPairMap == null) {
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
return;
}
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();
PackageBufINf bufInf;
if (condPairMap.isEmpty()) {
bufInf = showLogSum(c, buffer, packetId);
} else {
String logFile = condPairMap.get("file");
if (logFile == null) {
logFile = DEFAULT_LOGFILE;
}
String limitStr = condPairMap.get("limit");
limitStr = (limitStr != null) ? limitStr : "0," + 100000;
String[] limitArry = limitStr.split("\\s|,");
int start = Integer.parseInt(limitArry[0]);
int page = Integer.parseInt(limitArry[1]);
int end = start + page;
String key = condPairMap.get("key");
String regex = condPairMap.get("regex");
bufInf = showLogRange(c, buffer, packetId, key, regex, start, end, logFile);
}
packetId = bufInf.getPacketId();
buffer = bufInf.getBuffer();
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.
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.getPacketId();
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<UserSqlLastStat.SqlLast> queries = userStat.getSqlLastStat().getQueries();
int i = 1;
for (UserSqlLastStat.SqlLast sqlLast : queries) {
if (sqlLast != null) {
RowDataPacket row = getRow(user, sqlLast, i, c.getCharset().getResults());
row.setPacketId(++packetId);
i++;
buffer = row.write(buffer, c, true);
}
}
if (isClear) {
userStat.getSqlLastStat().clear();
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.
the class ShowSQLCondition 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.getPacketId();
String key = QueryConditionAnalyzer.getInstance().getKey();
List<Map.Entry<Object, AtomicLong>> list = QueryConditionAnalyzer.getInstance().getValues();
if (list != null) {
int size = list.size();
long total = 0L;
for (int i = 0; i < size; i++) {
Map.Entry<Object, AtomicLong> entry = list.get(i);
Object value = entry.getKey();
Long count = entry.getValue().get();
total += count;
RowDataPacket row = getRow(i, key, value.toString(), count, c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
RowDataPacket vkRow = getRow(size + 1, key + ".valuekey", "size", size, c.getCharset().getResults());
vkRow.setPacketId(++packetId);
buffer = vkRow.write(buffer, c, true);
RowDataPacket vcRow = getRow(size + 2, key + ".valuecount", "total", total, c.getCharset().getResults());
vcRow.setPacketId(++packetId);
buffer = vcRow.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.
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.getPacketId();
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().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
i++;
}
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.
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.getPacketId();
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<UserSqlLargeStat.SqlLarge> queries = userStat.getSqlLargeRowStat().getQueries();
for (UserSqlLargeStat.SqlLarge sql : queries) {
if (sql != null) {
RowDataPacket row = getRow(user, sql, c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
if (isClear) {
userStat.getSqlLargeRowStat().clear();
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations