use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowSQL method getRow.
private static RowDataPacket getRow(String user, UserSqlLastStat.SqlLast sql, int idx, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(idx));
row.add(StringUtil.encode(user, charset));
row.add(StringUtil.encode(FormatUtil.formatDate(sql.getStartTime()), charset));
row.add(LongUtil.toBytes(sql.getExecuteTime()));
row.add(StringUtil.encode(sql.getSql(), charset));
return row;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowSQLCondition method getRow.
private static RowDataPacket getRow(int i, String key, String value, long count, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(i));
row.add(StringUtil.encode(key, charset));
row.add(StringUtil.encode(value, charset));
row.add(LongUtil.toBytes(count));
return row;
}
use of com.actiontech.dble.net.mysql.RowDataPacket 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.RowDataPacket 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.RowDataPacket 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