Search in sources :

Example 6 with H2Client

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

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

the class ClusterModuleStandaloneProvider method prepare.

@Override
public void prepare(Properties config) throws ServiceNotProvidedException {
    this.dataMonitor = new ClusterStandaloneDataMonitor();
    final String url = config.getProperty(URL);
    final String userName = config.getProperty(USER_NAME);
    h2Client = new H2Client(url, userName, Const.EMPTY_STRING);
    this.dataMonitor.setClient(h2Client);
    this.registerServiceImplementation(ModuleListenerService.class, new StandaloneModuleListenerService(dataMonitor));
    this.registerServiceImplementation(ModuleRegisterService.class, new StandaloneModuleRegisterService(dataMonitor));
}
Also used : StandaloneModuleListenerService(org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleListenerService) StandaloneModuleRegisterService(org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleRegisterService) H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client)

Example 8 with H2Client

use of org.apache.skywalking.apm.collector.client.h2.H2Client 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 9 with H2Client

use of org.apache.skywalking.apm.collector.client.h2.H2Client 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 10 with H2Client

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

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