Search in sources :

Example 1 with TableStat

use of com.actiontech.dble.statistic.stat.TableStat in project dble by actiontech.

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.getPacketId();
    /*
        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().getResults());
                i++;
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) TableStat(com.actiontech.dble.statistic.stat.TableStat) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 2 with TableStat

use of com.actiontech.dble.statistic.stat.TableStat in project dble by actiontech.

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 found", charset));
        return row;
    }
    String table = tableStat.getTable();
    StringBuilder relationTableNameBuffer = new StringBuilder();
    StringBuilder relationTableCountBuffer = new StringBuilder();
    List<TableStat.RelationTable> relationTables = tableStat.getRelationTables();
    if (!relationTables.isEmpty()) {
        for (TableStat.RelationTable relationTable : relationTables) {
            relationTableNameBuffer.append(relationTable.getTableName()).append(", ");
            relationTableCountBuffer.append(relationTable.getCount()).append(", ");
        }
    } else {
        relationTableNameBuffer.append("NULL");
        relationTableCountBuffer.append("NULL");
    }
    row.add(StringUtil.encode(table, charset));
    long r = tableStat.getRCount();
    long w = tableStat.getWCount();
    row.add(LongUtil.toBytes(r));
    row.add(LongUtil.toBytes(w));
    String rStr = decimalFormat.format(1.0D * r / (r + w));
    row.add(StringUtil.encode(String.valueOf(rStr), charset));
    row.add(StringUtil.encode(relationTableNameBuffer.toString(), charset));
    row.add(StringUtil.encode(relationTableCountBuffer.toString(), charset));
    row.add(StringUtil.encode(FormatUtil.formatDate(tableStat.getLastExecuteTime()), charset));
    return row;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) TableStat(com.actiontech.dble.statistic.stat.TableStat)

Aggregations

RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)2 TableStat (com.actiontech.dble.statistic.stat.TableStat)2 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 ByteBuffer (java.nio.ByteBuffer)1