Search in sources :

Example 41 with H2Client

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

the class ApplicationComponentH2UIDAO method load.

@Override
public List<ApplicationComponent> load(Step step, long startTimeBucket, long endTimeBucket) {
    H2Client client = getClient();
    String tableName = TimePyramidTableNameBuilder.build(step, ApplicationComponentTable.TABLE);
    List<ApplicationComponent> applicationComponents = new LinkedList<>();
    String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_APPLICATION_ID, tableName, ApplicationComponentTable.COLUMN_TIME_BUCKET);
    Object[] params = new Object[] { startTimeBucket, endTimeBucket };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        while (rs.next()) {
            int applicationId = rs.getInt(ApplicationComponentTable.COLUMN_APPLICATION_ID);
            int componentId = rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID);
            ApplicationComponent applicationComponent = new ApplicationComponent();
            applicationComponent.setComponentId(componentId);
            applicationComponent.setApplicationId(applicationId);
            applicationComponents.add(applicationComponent);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return applicationComponents;
}
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 42 with H2Client

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

the class MemoryPoolMetricH2UIDAO method getMetric.

@Override
public JsonObject getMetric(int instanceId, long timeBucket, int poolType) {
    H2Client client = getClient();
    String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType;
    String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.COLUMN_ID);
    Object[] params = new Object[] { id };
    JsonObject metric = new JsonObject();
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            metric.addProperty("max", rs.getInt(MemoryPoolMetricTable.COLUMN_MAX));
            metric.addProperty("init", rs.getInt(MemoryPoolMetricTable.COLUMN_INIT));
            metric.addProperty("used", rs.getInt(MemoryPoolMetricTable.COLUMN_USED));
        } else {
            metric.addProperty("max", 0);
            metric.addProperty("init", 0);
            metric.addProperty("used", 0);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return metric;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JsonObject(com.google.gson.JsonObject) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) JsonObject(com.google.gson.JsonObject)

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