Search in sources :

Example 6 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class H2StorageInstaller method createTable.

@Override
protected boolean createTable(Client client, TableDefine tableDefine) throws StorageException {
    H2Client h2Client = (H2Client) client;
    H2TableDefine h2TableDefine = (H2TableDefine) tableDefine;
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("CREATE TABLE ").append(h2TableDefine.getName()).append(" (");
    h2TableDefine.getColumnDefines().forEach(columnDefine -> {
        H2ColumnDefine h2ColumnDefine = (H2ColumnDefine) columnDefine;
        if (h2ColumnDefine.getType().equals(H2ColumnDefine.Type.Varchar.name())) {
            sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append("(255),");
        } else {
            sqlBuilder.append(h2ColumnDefine.getName()).append(" ").append(h2ColumnDefine.getType()).append(",");
        }
    });
    // remove last comma
    sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length());
    sqlBuilder.append(")");
    try {
        logger.info("create h2 table with sql {}", sqlBuilder);
        h2Client.execute(sqlBuilder.toString());
    } catch (H2ClientException e) {
        throw new StorageInstallException(e.getMessage(), e);
    }
    return true;
}
Also used : StorageInstallException(org.apache.skywalking.apm.collector.storage.StorageInstallException) H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 7 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class CpuMetricH2UIDAO method getCPUTrend.

@Override
public List<Integer> getCPUTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
    H2Client client = getClient();
    String tableName = TimePyramidTableNameBuilder.build(step, CpuMetricTable.TABLE);
    String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, tableName, CpuMetricTable.COLUMN_ID);
    List<Integer> cpuTrends = new LinkedList<>();
    durationPoints.forEach(durationPoint -> {
        String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId;
        try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
            if (rs.next()) {
                double cpuUsed = rs.getDouble(CpuMetricTable.COLUMN_USAGE_PERCENT);
                long times = rs.getLong(CpuMetricTable.COLUMN_TIMES);
                cpuTrends.add((int) ((cpuUsed / times) * 100));
            } else {
                cpuTrends.add(0);
            }
        } catch (SQLException | H2ClientException e) {
            logger.error(e.getMessage(), e);
        }
    });
    return cpuTrends;
}
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)

Example 8 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class GlobalTraceH2UIDAO method getGlobalTraceId.

@Override
public List<String> getGlobalTraceId(String segmentId) {
    List<String> globalTraceIds = new ArrayList<>();
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_GLOBAL_TRACE_ID_SQL, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_SEGMENT_ID);
    Object[] params = new Object[] { segmentId };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        while (rs.next()) {
            String globalTraceId = rs.getString(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
            logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
            globalTraceIds.add(globalTraceId);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return globalTraceIds;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 9 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class InstanceH2UIDAO method instanceLastHeartBeatTime.

@Override
public Long instanceLastHeartBeatTime(long applicationInstanceId) {
    H2Client client = getClient();
    long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
    fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
    String sql = SqlBuilder.buildSql(GET_INST_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_INSTANCE_ID);
    Object[] params = new Object[] { fiveMinuteBefore, applicationInstanceId };
    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 10 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException 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)

Aggregations

H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)45 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)39 SQLException (java.sql.SQLException)37 ResultSet (java.sql.ResultSet)36 LinkedList (java.util.LinkedList)11 HashMap (java.util.HashMap)6 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 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 StorageException (org.apache.skywalking.apm.collector.storage.StorageException)1 H2SqlEntity (org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity)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