use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
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_plus by coderczp.
the class ShowSQLSumUser method getRow.
private static RowDataPacket getRow(UserStat userStat, long idx, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(idx));
if (userStat == null) {
row.add(StringUtil.encode(("not fond"), charset));
return row;
}
String user = userStat.getUser();
UserSqlRWStat rwStat = userStat.getRWStat();
long R = rwStat.getRCount();
long W = rwStat.getWCount();
String __R = decimalFormat.format(1.0D * R / (R + W));
int MAX = rwStat.getConcurrentMax();
row.add(StringUtil.encode(user, charset));
row.add(LongUtil.toBytes(R));
row.add(LongUtil.toBytes(W));
row.add(StringUtil.encode(String.valueOf(__R), charset));
row.add(StringUtil.encode(String.valueOf(MAX), charset));
row.add(LongUtil.toBytes(rwStat.getNetInBytes()));
row.add(LongUtil.toBytes(rwStat.getNetOutBytes()));
row.add(StringUtil.encode(rwStat.getExecuteHistogram().toString(), charset));
row.add(StringUtil.encode(rwStat.getTimeHistogram().toString(), charset));
row.add(LongUtil.toBytes(rwStat.getLastExecuteTime()));
return row;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowDataNode method getRow.
private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(node.getName(), charset));
row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
PhysicalDBPool pool = node.getDbPool();
PhysicalDatasource ds = pool.getSource();
if (ds != null) {
int active = ds.getActiveCountForSchema(node.getDatabase());
int idle = ds.getIdleCountForSchema(node.getDatabase());
row.add(IntegerUtil.toBytes(pool.getActivedIndex()));
row.add(StringUtil.encode(ds.getConfig().getDbType(), charset));
row.add(IntegerUtil.toBytes(active));
row.add(IntegerUtil.toBytes(idle));
row.add(IntegerUtil.toBytes(ds.getSize()));
} else {
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
}
row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
row.add(StringUtil.encode(nf.format(0), charset));
row.add(StringUtil.encode(nf.format(0), charset));
row.add(LongUtil.toBytes(0));
long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
return row;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowBackend method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c, true);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
buffer = eof.write(buffer, c, true);
byte packetId = eof.packetId;
String charset = c.getCharset();
for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
for (BackendConnection bc : p.getBackends().values()) {
if (bc != null) {
RowDataPacket row = getRow(bc, charset);
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowCollation 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.packetId;
RowDataPacket row = getRow(c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
// write lastEof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations