use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceH2CacheDAO method getInstanceIdByAddressId.
@Override
public int getInstanceIdByAddressId(int applicationId, int addressId) {
logger.info("get the instance id by application id = {}, address id = {}", applicationId, addressId);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_ADDRESS_ID, InstanceTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] { applicationId, addressId, BooleanUtils.TRUE };
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;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class ServiceNameH2CacheDAO method get.
@Override
public ServiceName get(int serviceId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
Object[] params = new Object[] { serviceId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
ServiceName serviceName = new ServiceName();
serviceName.setServiceId(serviceId);
serviceName.setApplicationId(rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID));
serviceName.setServiceName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME));
return serviceName;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class ApplicationMappingH2UIDAO method load.
@Override
public List<ApplicationMapping> load(Step step, long startTimeBucket, long endTimeBucket) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMappingTable.TABLE);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(APPLICATION_MAPPING_SQL, ApplicationMappingTable.COLUMN_APPLICATION_ID, ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, tableName, ApplicationMappingTable.COLUMN_TIME_BUCKET);
List<ApplicationMapping> applicationMappings = new LinkedList<>();
Object[] params = new Object[] { startTimeBucket, endTimeBucket };
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int applicationId = rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID);
int addressId = rs.getInt(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID);
ApplicationMapping applicationMapping = new ApplicationMapping();
applicationMapping.setApplicationId(applicationId);
applicationMapping.setMappingApplicationId(addressId);
applicationMappings.add(applicationMapping);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
logger.debug("node mapping data: {}", applicationMappings.toString());
return applicationMappings;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class GCMetricH2UIDAO method getGCTrend.
private List<Integer> getGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints, int gcPhrase) {
String tableName = TimePyramidTableNameBuilder.build(step, GCMetricTable.TABLE);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, tableName, GCMetricTable.COLUMN_ID);
List<Integer> gcTrends = new LinkedList<>();
durationPoints.forEach(durationPoint -> {
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + gcPhrase;
try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
if (rs.next()) {
long count = rs.getLong(GCMetricTable.COLUMN_COUNT);
long times = rs.getLong(GCMetricTable.COLUMN_TIMES);
gcTrends.add((int) (count / times));
} else {
gcTrends.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return gcTrends;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceMetricH2UIDAO method getResponseTimeTrend.
@Override
public List<Integer> getResponseTimeTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
H2Client client = getClient();
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, tableName, InstanceMetricTable.COLUMN_ID);
List<Integer> responseTimeTrends = new LinkedList<>();
durationPoints.forEach(durationPoint -> {
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
try (ResultSet rs = client.executeQuery(sql, new Object[] { id })) {
if (rs.next()) {
long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS);
long durationSum = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
responseTimeTrends.add((int) (durationSum / callTimes));
} else {
responseTimeTrends.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return responseTimeTrends;
}
Aggregations