use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class NetworkAddressH2UIDAO method getNumOfSpanLayer.
@Override
public int getNumOfSpanLayer(int spanLayer) {
String dynamicSql = "select count({0}) as cnt from {1} where {2} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, NetworkAddressTable.COLUMN_NETWORK_ADDRESS, NetworkAddressTable.TABLE, NetworkAddressTable.COLUMN_SPAN_LAYER);
Object[] params = new Object[] { spanLayer };
try (ResultSet rs = getClient().executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt("cnt");
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException 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;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class SegmentDurationH2UIDAO method loadTop.
@Override
public TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration, String operationName, int applicationId, int limit, int from, String... segmentIds) {
H2Client client = getClient();
String sql = "select * from {0} where {1} >= ? and {1} <= ?";
List<Object> params = new ArrayList<>();
List<Object> columns = new ArrayList<>();
columns.add(SegmentDurationTable.TABLE);
columns.add(SegmentDurationTable.COLUMN_TIME_BUCKET);
params.add(startSecondTimeBucket);
params.add(endSecondTimeBucket);
int paramIndex = 1;
if (minDuration != -1 || maxDuration != -1) {
if (minDuration != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} >= ?";
params.add(minDuration);
columns.add(SegmentDurationTable.COLUMN_DURATION);
}
if (maxDuration != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} <= ?";
params.add(maxDuration);
columns.add(SegmentDurationTable.COLUMN_DURATION);
}
}
if (StringUtils.isNotEmpty(operationName)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(operationName);
columns.add(SegmentDurationTable.COLUMN_SERVICE_NAME);
}
if (StringUtils.isNotEmpty(segmentIds)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(segmentIds);
columns.add(SegmentDurationTable.COLUMN_TRACE_ID);
}
if (applicationId != 0) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(applicationId);
columns.add(SegmentDurationTable.COLUMN_APPLICATION_ID);
}
sql = sql + " limit " + from + "," + limit;
sql = SqlBuilder.buildSql(sql, columns);
Object[] p = params.toArray(new Object[0]);
TraceBrief traceBrief = new TraceBrief();
int cnt = 0;
try (ResultSet rs = client.executeQuery(sql, p)) {
while (rs.next()) {
BasicTrace basicTrace = new BasicTrace();
basicTrace.setSegmentId(rs.getString(SegmentDurationTable.COLUMN_SEGMENT_ID));
basicTrace.setDuration(rs.getInt(SegmentDurationTable.COLUMN_DURATION));
basicTrace.setStart(rs.getLong(SegmentDurationTable.COLUMN_START_TIME));
basicTrace.setOperationName(rs.getString(SegmentDurationTable.COLUMN_SERVICE_NAME));
basicTrace.setError(BooleanUtils.valueToBoolean(rs.getInt(SegmentDurationTable.COLUMN_IS_ERROR)));
traceBrief.getTraces().add(basicTrace);
cnt++;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
traceBrief.setTotal(cnt);
return traceBrief;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceH2CacheDAO method getApplicationId.
@Override
public int getApplicationId(int instanceId) {
logger.info("get the application id by instance id = {}", instanceId);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] { instanceId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceH2CacheDAO method getInstanceIdByAgentUUID.
@Override
public int getInstanceIdByAgentUUID(int applicationId, String agentUUID) {
logger.info("get the instance id by application id = {}, agentUUID = {}", applicationId, agentUUID);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_AGENT_UUID, InstanceTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] { applicationId, agentUUID, BooleanUtils.FALSE };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(InstanceTable.COLUMN_INSTANCE_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
Aggregations