use of io.mycat.statistic.stat.TableStat in project Mycat_plus by coderczp.
the class ShowSQLSumTable method getRow.
private static RowDataPacket getRow(TableStat tableStat, long idx, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(idx));
if (tableStat == null) {
row.add(StringUtil.encode(("not fond"), charset));
return row;
}
String table = tableStat.getTable();
long R = tableStat.getRCount();
long W = tableStat.getWCount();
String __R = decimalFormat.format(1.0D * R / (R + W));
StringBuffer relaTableNameBuffer = new StringBuffer();
StringBuffer relaTableCountBuffer = new StringBuffer();
List<TableStat.RelaTable> relaTables = tableStat.getRelaTables();
if (!relaTables.isEmpty()) {
for (TableStat.RelaTable relaTable : relaTables) {
relaTableNameBuffer.append(relaTable.getTableName()).append(", ");
relaTableCountBuffer.append(relaTable.getCount()).append(", ");
}
} else {
relaTableNameBuffer.append("NULL");
relaTableCountBuffer.append("NULL");
}
row.add(StringUtil.encode(table, charset));
row.add(LongUtil.toBytes(R));
row.add(LongUtil.toBytes(W));
row.add(StringUtil.encode(String.valueOf(__R), charset));
row.add(StringUtil.encode(relaTableNameBuffer.toString(), charset));
row.add(StringUtil.encode(relaTableCountBuffer.toString(), charset));
row.add(LongUtil.toBytes(tableStat.getLastExecuteTime()));
return row;
}
use of io.mycat.statistic.stat.TableStat 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.statistic.stat.TableStat in project Mycat_plus by coderczp.
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.statistic.stat.TableStat in project Mycat-Server by MyCATApache.
the class ShowSQLSumTable method getRow.
private static RowDataPacket getRow(TableStat tableStat, long idx, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(idx));
if (tableStat == null) {
row.add(StringUtil.encode(("not fond"), charset));
return row;
}
String table = tableStat.getTable();
long R = tableStat.getRCount();
long W = tableStat.getWCount();
String __R = decimalFormat.format(1.0D * R / (R + W));
StringBuffer relaTableNameBuffer = new StringBuffer();
StringBuffer relaTableCountBuffer = new StringBuffer();
List<TableStat.RelaTable> relaTables = tableStat.getRelaTables();
if (!relaTables.isEmpty()) {
for (TableStat.RelaTable relaTable : relaTables) {
relaTableNameBuffer.append(relaTable.getTableName()).append(", ");
relaTableCountBuffer.append(relaTable.getCount()).append(", ");
}
} else {
relaTableNameBuffer.append("NULL");
relaTableCountBuffer.append("NULL");
}
row.add(StringUtil.encode(table, charset));
row.add(LongUtil.toBytes(R));
row.add(LongUtil.toBytes(W));
row.add(StringUtil.encode(String.valueOf(__R), charset));
row.add(StringUtil.encode(relaTableNameBuffer.toString(), charset));
row.add(StringUtil.encode(relaTableCountBuffer.toString(), charset));
row.add(LongUtil.toBytes(tableStat.getLastExecuteTime()));
return row;
}
Aggregations