Search in sources :

Example 11 with Instance

use of org.apache.skywalking.apm.collector.storage.table.register.Instance in project incubator-skywalking by apache.

the class InstanceHeartBeatH2PersistenceDAO method get.

@Override
public Instance get(String id) {
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
    Object[] params = new Object[] { id };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            Instance instance = new Instance();
            instance.setId(id);
            instance.setInstanceId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
            instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME));
            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 12 with Instance

use of org.apache.skywalking.apm.collector.storage.table.register.Instance in project incubator-skywalking by apache.

the class InstanceMetricAlarmAssertWorker method generateAlarmContent.

@Override
protected void generateAlarmContent(InstanceAlarm alarm, double threshold) {
    Instance instance = instanceDAO.getInstance(alarm.getInstanceId());
    JsonObject osInfo = gson.fromJson(instance.getOsInfo(), JsonObject.class);
    String serverName = Const.UNKNOWN;
    if (osInfo.has("hostName")) {
        serverName = osInfo.get("hostName").getAsString();
    }
    String clientOrServer = "server";
    if (MetricSource.Caller.getValue() == alarm.getSourceValue()) {
        clientOrServer = "client";
    }
    if (AlarmType.ERROR_RATE.getValue() == alarm.getAlarmType()) {
        alarm.setAlarmContent("The success rate of " + serverName + ", detected from " + clientOrServer + " side, is lower than " + threshold + " rate.");
    } else if (AlarmType.SLOW_RTT.getValue() == alarm.getAlarmType()) {
        alarm.setAlarmContent("Response time of " + serverName + ", detected from " + clientOrServer + " side, is slower than " + threshold + " ms.");
    }
}
Also used : Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) JsonObject(com.google.gson.JsonObject)

Aggregations

Instance (org.apache.skywalking.apm.collector.storage.table.register.Instance)12 JsonObject (com.google.gson.JsonObject)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)2 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 HashMap (java.util.HashMap)1 Alarm (org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm)1 AppServerInfo (org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo)1 DurationPoint (org.apache.skywalking.apm.collector.storage.utils.DurationPoint)1 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)1