use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class InstanceHeartBeatH2PersistenceDAO method get.
@Override
public Instance get(String id) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] { id };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
Instance instance = new Instance();
instance.setId(id);
instance.setInstanceId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME));
return instance;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class GlobalTraceH2UIDAO method getSegmentIds.
@Override
public List<String> getSegmentIds(String globalTraceId) {
List<String> segmentIds = new ArrayList<>();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SEGMENT_IDS_SQL, GlobalTraceTable.COLUMN_SEGMENT_ID, GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
Object[] params = new Object[] { globalTraceId };
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
String segmentId = rs.getString(GlobalTraceTable.COLUMN_SEGMENT_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
segmentIds.add(segmentId);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return segmentIds;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class InstanceH2UIDAO method buildAppServerInfo.
private List<AppServerInfo> buildAppServerInfo(String sql, Object[] params) {
H2Client client = getClient();
List<AppServerInfo> appServerInfos = new LinkedList<>();
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
appServerInfo.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO));
appServerInfos.add(appServerInfo);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return appServerInfos;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class MemoryMetricH2UIDAO method getMemoryTrend.
private Trend getMemoryTrend(int instanceId, Step step, List<DurationPoint> durationPoints, boolean isHeap) {
String tableName = TimePyramidTableNameBuilder.build(step, MemoryMetricTable.TABLE);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, tableName, MemoryMetricTable.COLUMN_ID);
Trend trend = new Trend();
durationPoints.forEach(durationPoint -> {
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + BooleanUtils.booleanToValue(isHeap);
try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
if (rs.next()) {
long max = rs.getLong(MemoryMetricTable.COLUMN_MAX);
long used = rs.getLong(MemoryMetricTable.COLUMN_USED);
long times = rs.getLong(MemoryMetricTable.COLUMN_TIMES);
trend.getMetrics().add((int) (used / times));
if (max < 0) {
trend.getMaxMetrics().add((int) (used / times));
} else {
trend.getMaxMetrics().add((int) (max / times));
}
} else {
trend.getMetrics().add(0);
trend.getMaxMetrics().add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return trend;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class ServiceMetricH2UIDAO method getServiceSLATrend.
@Override
public List<Integer> getServiceSLATrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
H2Client client = getClient();
String dynamicSql = "select * from {0} where {1} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, tableName, ServiceMetricTable.COLUMN_ID);
List<Integer> trends = new LinkedList<>();
durationPoints.forEach(durationPoint -> {
String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
if (rs.next()) {
long calls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
long errorCalls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
trends.add((int) (((calls - errorCalls) / calls)) * 10000);
} else {
trends.add(10000);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return trends;
}
Aggregations