use of org.apache.skywalking.apm.collector.client.h2.H2Client 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;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class InstanceH2UIDAO method getInstance.
@Override
public Instance getInstance(int instanceId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] { instanceId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
Instance instance = new Instance();
instance.setId(rs.getString(InstanceTable.COLUMN_ID));
instance.setApplicationId(rs.getInt(InstanceTable.COLUMN_APPLICATION_ID));
instance.setAgentUUID(rs.getString(InstanceTable.COLUMN_AGENT_UUID));
instance.setRegisterTime(rs.getLong(InstanceTable.COLUMN_REGISTER_TIME));
instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME));
instance.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO));
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 InstanceH2UIDAO method getApplications.
@Override
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds) {
H2Client client = getClient();
List<Application> applications = new LinkedList<>();
String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[] { startSecondTimeBucket };
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Integer applicationId = rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
logger.debug("applicationId: {}", applicationId);
Application application = new Application();
application.setId(applicationId);
application.setNumOfServer(rs.getInt("cnt"));
applications.add(application);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return applications;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class SegmentH2UIDAO method load.
@Override
public TraceSegmentObject load(String segmentId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY, SegmentTable.TABLE, SegmentTable.COLUMN_ID);
Object[] params = new Object[] { segmentId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
byte[] dataBinary = rs.getBytes(SegmentTable.COLUMN_DATA_BINARY);
try {
return TraceSegmentObject.parseFrom(dataBinary);
} catch (InvalidProtocolBufferException e) {
logger.error(e.getMessage(), e);
}
}
} 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 ServiceMetricH2UIDAO method getServiceResponseTimeTrend.
@Override
public List<Integer> getServiceResponseTimeTrend(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 durationSum = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
trends.add((int) (durationSum / calls));
} else {
trends.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return trends;
}
Aggregations