use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowSQLDetail method execute.
public static void execute(ManagerConnection c, long sql) {
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;
for (int i = 0; i < 3; i++) {
RowDataPacket row = getRow(sql, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
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.packetId;
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());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
i++;
}
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket 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);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowSQLSumTable 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;
/*
int i=0;
Map<String, TableStat> statMap = TableStatAnalyzer.getInstance().getTableStatMap();
for (TableStat tableStat : statMap.values()) {
i++;
RowDataPacket row = getRow(tableStat,i, c.getCharset());//getRow(sqlStat,sql, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c,true);
}
*/
List<TableStat> list = TableStatAnalyzer.getInstance().getTableStats(isClear);
if (list != null) {
int i = 1;
for (TableStat tableStat : list) {
if (tableStat != null) {
RowDataPacket row = getRow(tableStat, i, c.getCharset());
i++;
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowServer method getRow.
private static RowDataPacket getRow(String charset) {
MycatServer server = MycatServer.getInstance();
long startupTime = server.getStartupTime();
long now = TimeUtil.currentTimeMillis();
long uptime = now - startupTime;
Runtime rt = Runtime.getRuntime();
long total = rt.totalMemory();
long max = rt.maxMemory();
long used = (total - rt.freeMemory());
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(FormatUtil.formatTime(uptime, 3), charset));
row.add(LongUtil.toBytes(used));
row.add(LongUtil.toBytes(total));
row.add(LongUtil.toBytes(max));
row.add(LongUtil.toBytes(server.getConfig().getReloadTime()));
row.add(LongUtil.toBytes(server.getConfig().getRollbackTime()));
row.add(StringUtil.encode(charset, charset));
row.add(StringUtil.encode(MycatServer.getInstance().isOnline() ? "ON" : "OFF", charset));
return row;
}
Aggregations