Search in sources :

Example 36 with H2Client

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

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

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

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

the class ApplicationRegisterH2DAO method save.

@Override
public void save(Application application) {
    H2Client client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(ApplicationTable.COLUMN_ID, application.getId());
    source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode());
    source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId());
    source.put(ApplicationTable.COLUMN_ADDRESS_ID, application.getAddressId());
    source.put(ApplicationTable.COLUMN_IS_ADDRESS, application.getIsAddress());
    String sql = SqlBuilder.buildBatchInsertSql(ApplicationTable.TABLE, source.keySet());
    Object[] params = source.values().toArray(new Object[0]);
    try {
        client.execute(sql, params);
    } catch (H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) HashMap(java.util.HashMap) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 40 with H2Client

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

the class NetworkAddressRegisterH2DAO method update.

@Override
public void update(String id, int spanLayer, int serverType) {
    H2Client client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(NetworkAddressTable.COLUMN_SPAN_LAYER, spanLayer);
    source.put(NetworkAddressTable.COLUMN_SERVER_TYPE, serverType);
    String sql = SqlBuilder.buildBatchUpdateSql(InstanceTable.TABLE, source.keySet(), InstanceTable.COLUMN_INSTANCE_ID);
    Object[] params = source.values().toArray(new Object[] { id });
    try {
        client.execute(sql, params);
    } catch (H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) HashMap(java.util.HashMap) 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