Search in sources :

Example 11 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 12 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 13 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) Application(org.apache.skywalking.apm.collector.storage.ui.application.Application) LinkedList(java.util.LinkedList)

Example 14 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject)

Example 15 with H2Client

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) LinkedList(java.util.LinkedList)

Aggregations

H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)41 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)40 ResultSet (java.sql.ResultSet)32 SQLException (java.sql.SQLException)32 LinkedList (java.util.LinkedList)10 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)3 StorageInstallException (org.apache.skywalking.apm.collector.storage.StorageInstallException)2 Instance (org.apache.skywalking.apm.collector.storage.table.register.Instance)2 JsonObject (com.google.gson.JsonObject)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 StandaloneModuleListenerService (org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleListenerService)1 StandaloneModuleRegisterService (org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleRegisterService)1 StorageException (org.apache.skywalking.apm.collector.storage.StorageException)1 BatchH2DAO (org.apache.skywalking.apm.collector.storage.h2.base.dao.BatchH2DAO)1 H2StorageInstaller (org.apache.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 NetworkAddress (org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)1 ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)1 Application (org.apache.skywalking.apm.collector.storage.ui.application.Application)1