use of io.mycat.statistic.SQLRecord 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.SQLRecord in project Mycat_plus by coderczp.
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.SQLRecord in project Mycat_plus by coderczp.
the class UserStat method update.
/**
* 更新状态
*
* @param sqlType
* @param sql
* @param startTime
*/
public void update(int sqlType, String sql, long sqlRows, long netInBytes, long netOutBytes, long startTime, long endTime, int rseultSetSize) {
// before 计算最大并发数
// -----------------------------------------------------
int invoking = runningCount.incrementAndGet();
for (; ; ) {
int max = concurrentMax.get();
if (invoking > max) {
if (concurrentMax.compareAndSet(max, invoking)) {
break;
}
} else {
break;
}
}
// -----------------------------------------------------
// this.lock.writeLock().lock();
// try {
// 慢查询记录
long executeTime = endTime - startTime;
if (executeTime >= SQL_SLOW_TIME) {
SQLRecord record = new SQLRecord();
record.executeTime = executeTime;
record.statement = sql;
record.startTime = startTime;
this.sqlRecorder.add(record);
}
// 执行状态记录
this.sqlRwStat.setConcurrentMax(concurrentMax.get());
this.sqlRwStat.add(sqlType, sql, executeTime, netInBytes, netOutBytes, startTime, endTime);
// 记录最新执行的SQL
this.sqlLastStat.add(sql, executeTime, startTime, endTime);
// 记录高频SQL
this.sqlHighStat.addSql(sql, executeTime, startTime, endTime);
// 记录SQL Select 返回超过 10000 行的 大结果集
if (sqlType == ServerParse.SELECT && sqlRows > 10000) {
this.sqlLargeStat.add(sql, sqlRows, executeTime, startTime, endTime);
}
// 记录超过阈值的大结果集sql
if (rseultSetSize >= MycatServer.getInstance().getConfig().getSystem().getMaxResultSet()) {
this.sqlResultSizeRecorder.addSql(sql, rseultSetSize);
}
// } finally {
// this.lock.writeLock().unlock();
// }
// after
// -----------------------------------------------------
runningCount.decrementAndGet();
}
use of io.mycat.statistic.SQLRecord in project Mycat-Server by MyCATApache.
the class UserStat method update.
/**
* 更新状态
*
* @param sqlType
* @param sql
* @param startTime
*/
public void update(int sqlType, String sql, long sqlRows, long netInBytes, long netOutBytes, long startTime, long endTime, int rseultSetSize) {
// before 计算最大并发数
// -----------------------------------------------------
int invoking = runningCount.incrementAndGet();
for (; ; ) {
int max = concurrentMax.get();
if (invoking > max) {
if (concurrentMax.compareAndSet(max, invoking)) {
break;
}
} else {
break;
}
}
// -----------------------------------------------------
// this.lock.writeLock().lock();
// try {
// 慢查询记录
long executeTime = endTime - startTime;
if (executeTime >= SQL_SLOW_TIME) {
SQLRecord record = new SQLRecord();
record.executeTime = executeTime;
record.statement = sql;
record.startTime = startTime;
this.sqlRecorder.add(record);
}
// 执行状态记录
this.sqlRwStat.setConcurrentMax(concurrentMax.get());
this.sqlRwStat.add(sqlType, sql, executeTime, netInBytes, netOutBytes, startTime, endTime);
// 记录最新执行的SQL
this.sqlLastStat.add(sql, executeTime, startTime, endTime);
// 记录高频SQL
this.sqlHighStat.addSql(sql, executeTime, startTime, endTime);
// 记录SQL Select 返回超过 10000 行的 大结果集
if (sqlType == ServerParse.SELECT && sqlRows > 10000) {
this.sqlLargeStat.add(sql, sqlRows, executeTime, startTime, endTime);
}
// 记录超过阈值的大结果集sql
if (rseultSetSize >= MycatServer.getInstance().getConfig().getSystem().getMaxResultSet()) {
this.sqlResultSizeRecorder.addSql(sql, rseultSetSize);
}
// } finally {
// this.lock.writeLock().unlock();
// }
// after
// -----------------------------------------------------
runningCount.decrementAndGet();
}
Aggregations