use of io.mycat.statistic.stat.UserStat 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.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
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.packetId;
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<UserSqlLastStat.SqlLast> sqls = userStat.getSqlLastStat().getSqls();
int i = 1;
for (UserSqlLastStat.SqlLast sqlLast : sqls) {
if (sqlLast != null) {
RowDataPacket row = getRow(user, sqlLast, i, c.getCharset());
row.packetId = ++packetId;
i++;
buffer = row.write(buffer, c, true);
}
}
//读取SQL监控后清理
if (isClear) {
userStat.getSqlLastStat().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.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
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();
}
StringBuilder s = new StringBuilder();
s.append(c).append("Reset show @@sql @@sql.sum @@sql.slow success by manager");
logger.warn(s.toString());
OkPacket ok = new OkPacket();
ok.packetId = 1;
ok.affectedRows = 1;
ok.serverStatus = 2;
ok.message = "Reset show @@sql @@sql.sum @@sql.slow success".getBytes();
ok.write(c);
}
use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
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.packetId;
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<UserSqlLargeStat.SqlLarge> sqls = userStat.getSqlLargeRowStat().getSqls();
for (UserSqlLargeStat.SqlLarge sql : sqls) {
if (sql != null) {
RowDataPacket row = getRow(user, sql, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
if (isClear) {
//读取大结果集SQL后,清理
userStat.getSqlLargeRowStat().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.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
the class ShowSQLSumUser 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, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
i++;
//getRow(sqlStat,sql, c.getCharset());
RowDataPacket row = getRow(userStat, i, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
if (isClear) {
userStat.clearRwStat();
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations