use of com.alibaba.cobar.statistic.SQLRecord in project cobar by alibaba.
the class ShowSQLSlow method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
SQLRecord[] records = CobarServer.getInstance().getSqlRecorder().getRecords();
for (int i = records.length - 1; i >= 0; i--) {
if (records[i] != null) {
RowDataPacket row = getRow(records[i], c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
use of com.alibaba.cobar.statistic.SQLRecord in project cobar by alibaba.
the class ShowSlow method dataNode.
public static void dataNode(ManagerConnection c, String name) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
CobarConfig conf = CobarServer.getInstance().getConfig();
MySQLDataNode dn = conf.getDataNodes().get(name);
MySQLDataSource ds = null;
if (dn != null && (ds = dn.getSource()) != null) {
SQLRecord[] records = ds.getSqlRecorder().getRecords();
for (int i = records.length - 1; i >= 0; i--) {
if (records[i] != null) {
RowDataPacket row = getRow(records[i], c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
use of com.alibaba.cobar.statistic.SQLRecord in project cobar by alibaba.
the class ShowSlow method schema.
public static void schema(ManagerConnection c, String name) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
CobarConfig conf = CobarServer.getInstance().getConfig();
SchemaConfig schema = conf.getSchemas().get(name);
if (schema != null) {
SQLRecorder recorder = new SQLRecorder(conf.getSystem().getSqlRecordCount());
Map<String, MySQLDataNode> dataNodes = conf.getDataNodes();
for (String n : schema.getAllDataNodes()) {
MySQLDataNode dn = dataNodes.get(n);
MySQLDataSource ds = null;
if (dn != null && (ds = dn.getSource()) != null) {
for (SQLRecord r : ds.getSqlRecorder().getRecords()) {
if (r != null && recorder.check(r.executeTime)) {
recorder.add(r);
}
}
}
}
SQLRecord[] records = recorder.getRecords();
for (int i = records.length - 1; i >= 0; i--) {
if (records[i] != null) {
RowDataPacket row = getRow(records[i], c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
use of com.alibaba.cobar.statistic.SQLRecord in project cobar by alibaba.
the class MySQLChannel method recordSql.
/**
* 记录sql执行信息
*/
private void recordSql(String host, String schema, String stmt) {
long time = TimeUtil.currentTimeMillis() - lastActiveTime;
SQLRecorder sqlRecorder = dataSource.getSqlRecorder();
if (sqlRecorder.check(time)) {
SQLRecord recorder = new SQLRecord();
recorder.host = host;
recorder.schema = schema;
recorder.statement = stmt;
recorder.startTime = lastActiveTime;
recorder.executeTime = time;
recorder.dataNode = dataSource.getName();
recorder.dataNodeIndex = dataSource.getIndex();
sqlRecorder.add(recorder);
}
}
use of com.alibaba.cobar.statistic.SQLRecord in project cobar by alibaba.
the class MySQLConnection method recordSql.
/**
* 记录sql执行信息
*/
public void recordSql(String host, String schema, String stmt) {
final long now = TimeUtil.currentTimeMillis();
if (now > this.lastTime) {
long time = now - this.lastTime;
SQLRecorder sqlRecorder = this.pool.getSqlRecorder();
if (sqlRecorder.check(time)) {
SQLRecord recorder = new SQLRecord();
recorder.host = host;
recorder.schema = schema;
recorder.statement = stmt;
recorder.startTime = lastTime;
recorder.executeTime = time;
recorder.dataNode = pool.getName();
recorder.dataNodeIndex = pool.getIndex();
sqlRecorder.add(recorder);
}
}
this.lastTime = now;
}
Aggregations