use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class H2StorageInstaller method createTable.
@Override
protected boolean createTable(Client client, TableDefine tableDefine) throws StorageException {
H2Client h2Client = (H2Client) client;
H2TableDefine h2TableDefine = (H2TableDefine) tableDefine;
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("CREATE TABLE ").append(h2TableDefine.getName()).append(" (");
h2TableDefine.getColumnDefines().forEach(columnDefine -> {
H2ColumnDefine h2ColumnDefine = (H2ColumnDefine) columnDefine;
if (h2ColumnDefine.getType().equals(H2ColumnDefine.Type.Varchar.name())) {
sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append("(255),");
} else {
sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append(",");
}
});
// remove last comma
sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length());
sqlBuilder.append(")");
try {
logger.info("create h2 table with sql {}", sqlBuilder);
h2Client.execute(sqlBuilder.toString());
} catch (H2ClientException e) {
throw new StorageInstallException(e.getMessage(), e);
}
return true;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class CpuMetricH2UIDAO method getCPUTrend.
@Override
public List<Integer> getCPUTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
H2Client client = getClient();
String tableName = TimePyramidTableNameBuilder.build(step, CpuMetricTable.TABLE);
String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, tableName, CpuMetricTable.COLUMN_ID);
List<Integer> cpuTrends = new LinkedList<>();
durationPoints.forEach(durationPoint -> {
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId;
try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
if (rs.next()) {
double cpuUsed = rs.getDouble(CpuMetricTable.COLUMN_USAGE_PERCENT);
long times = rs.getLong(CpuMetricTable.COLUMN_TIMES);
cpuTrends.add((int) ((cpuUsed / times) * 100));
} else {
cpuTrends.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return cpuTrends;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class GlobalTraceH2UIDAO method getGlobalTraceId.
@Override
public List<String> getGlobalTraceId(String segmentId) {
List<String> globalTraceIds = new ArrayList<>();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_GLOBAL_TRACE_ID_SQL, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_SEGMENT_ID);
Object[] params = new Object[] { segmentId };
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
String globalTraceId = rs.getString(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
globalTraceIds.add(globalTraceId);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return globalTraceIds;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceH2UIDAO method instanceLastHeartBeatTime.
@Override
public Long instanceLastHeartBeatTime(long applicationInstanceId) {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_INST_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] { fiveMinuteBefore, applicationInstanceId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0L;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceH2UIDAO method lastHeartBeatTime.
@Override
public Long lastHeartBeatTime() {
H2Client client = getClient();
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME);
Object[] params = new Object[] { fiveMinuteBefore };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0L;
}
Aggregations