use of com.actiontech.dble.backend.heartbeat.DBHeartbeat in project dble by actiontech.
the class ShowHeartbeatDetail method getRows.
private static List<RowDataPacket> getRows(String name, String charset) {
List<RowDataPacket> list = new LinkedList<>();
ServerConfig conf = DbleServer.getInstance().getConfig();
String ip = "";
int port = 0;
DBHeartbeat hb = null;
Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
for (PhysicalDBPool pool : dataHosts.values()) {
for (PhysicalDatasource ds : pool.getAllDataSources()) {
if (name.equals(ds.getName())) {
hb = ds.getHeartbeat();
ip = ds.getConfig().getIp();
port = ds.getConfig().getPort();
break;
}
}
}
if (hb != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Queue<HeartbeatRecorder.Record> heartbeatRecorders = hb.getRecorder().getRecordsAll();
for (HeartbeatRecorder.Record record : heartbeatRecorders) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(name, charset));
row.add(StringUtil.encode(ip, charset));
row.add(IntegerUtil.toBytes(port));
long time = record.getTime();
String timeStr = sdf.format(new Date(time));
row.add(StringUtil.encode(timeStr, charset));
row.add(LongUtil.toBytes(record.getValue()));
list.add(row);
}
} else {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
list.add(row);
}
return list;
}
Aggregations