Search in sources :

Example 1 with Instance

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

the class InstanceHeartBeatService method heartBeat.

@Override
public void heartBeat(int instanceId, long heartBeatTime) {
    Instance instance = new Instance();
    instance.setId(String.valueOf(instanceId));
    instance.setHeartBeatTime(TimeBucketUtils.INSTANCE.getSecondTimeBucket(heartBeatTime));
    instance.setInstanceId(instanceId);
    logger.debug("push to instance heart beat persistence worker, id: {}", instance.getId());
    getHeartBeatGraph().start(instance);
}
Also used : Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance)

Example 2 with Instance

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

the class InstanceRegisterSerialWorker method onWork.

@Override
protected void onWork(Instance instance) throws WorkerException {
    logger.debug("register instance, application id: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID());
    int instanceId;
    if (BooleanUtils.valueToBoolean(instance.getIsAddress())) {
        instanceId = instanceCacheService.getInstanceIdByAddressId(instance.getApplicationId(), instance.getAddressId());
    } else {
        instanceId = instanceCacheService.getInstanceIdByAgentUUID(instance.getApplicationId(), instance.getAgentUUID());
    }
    if (instanceId == 0) {
        Instance newInstance;
        int min = instanceRegisterDAO.getMinInstanceId();
        int max = instanceRegisterDAO.getMaxInstanceId();
        if (min == 0 && max == 0) {
            Instance userInstance = new Instance();
            userInstance.setId(String.valueOf(Const.NONE_INSTANCE_ID));
            userInstance.setInstanceId(Const.NONE_INSTANCE_ID);
            userInstance.setApplicationId(Const.NONE_APPLICATION_ID);
            userInstance.setApplicationCode(Const.USER_CODE);
            userInstance.setAgentUUID(Const.USER_CODE);
            userInstance.setHeartBeatTime(System.currentTimeMillis());
            userInstance.setOsInfo(Const.EMPTY_STRING);
            userInstance.setRegisterTime(System.currentTimeMillis());
            userInstance.setAddressId(Const.NONE);
            userInstance.setIsAddress(BooleanUtils.FALSE);
            instanceRegisterDAO.save(userInstance);
            newInstance = new Instance();
            newInstance.setId("2");
            newInstance.setInstanceId(2);
            newInstance.setApplicationId(instance.getApplicationId());
            newInstance.setApplicationCode(instance.getApplicationCode());
            newInstance.setAgentUUID(instance.getAgentUUID());
            newInstance.setHeartBeatTime(instance.getHeartBeatTime());
            newInstance.setOsInfo(instance.getOsInfo());
            newInstance.setRegisterTime(instance.getRegisterTime());
            newInstance.setAddressId(instance.getAddressId());
            newInstance.setIsAddress(instance.getIsAddress());
        } else {
            newInstance = new Instance();
            newInstance.setId(String.valueOf(max + 1));
            newInstance.setInstanceId(max + 1);
            newInstance.setApplicationId(instance.getApplicationId());
            newInstance.setApplicationCode(instance.getApplicationCode());
            newInstance.setAgentUUID(instance.getAgentUUID());
            newInstance.setHeartBeatTime(instance.getHeartBeatTime());
            newInstance.setOsInfo(instance.getOsInfo());
            newInstance.setRegisterTime(instance.getRegisterTime());
            newInstance.setAddressId(instance.getAddressId());
            newInstance.setIsAddress(instance.getIsAddress());
        }
        instanceRegisterDAO.save(newInstance);
    }
}
Also used : Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance)

Example 3 with Instance

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

the class InstanceReferenceMetricAlarmAssertWorker method generateAlarmContent.

@Override
protected void generateAlarmContent(InstanceReferenceAlarm alarm, double threshold) {
    Instance instance = instanceDAO.getInstance(alarm.getBehindInstanceId());
    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 + ".");
    } else if (AlarmType.SLOW_RTT.getValue() == alarm.getAlarmType()) {
        alarm.setAlarmContent("Response time of " + serverName + ", detected from " + clientOrServer + " side, is slower than " + threshold + ".");
    }
}
Also used : Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) JsonObject(com.google.gson.JsonObject)

Example 4 with Instance

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

the class InstanceEsUIDAO method getInstance.

@Override
public Instance getInstance(int instanceId) {
    logger.debug("get instance info, instance id: {}", instanceId);
    GetRequestBuilder requestBuilder = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(instanceId));
    GetResponse getResponse = requestBuilder.get();
    if (getResponse.isExists()) {
        Instance instance = new Instance();
        instance.setId(getResponse.getId());
        instance.setApplicationId(((Number) getResponse.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue());
        instance.setAgentUUID((String) getResponse.getSource().get(InstanceTable.COLUMN_AGENT_UUID));
        instance.setRegisterTime(((Number) getResponse.getSource().get(InstanceTable.COLUMN_REGISTER_TIME)).longValue());
        instance.setHeartBeatTime(((Number) getResponse.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
        instance.setOsInfo((String) getResponse.getSource().get(InstanceTable.COLUMN_OS_INFO));
        return instance;
    }
    return null;
}
Also used : Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 5 with Instance

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

the class AlarmService method loadInstanceAlarmList.

public Alarm loadInstanceAlarmList(String keyword, Step step, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException {
    logger.debug("keyword: {}, startTimeBucket: {}, endTimeBucket: {}, limit: {}, from: {}", keyword, startTimeBucket, endTimeBucket, limit, from);
    Alarm alarm = instanceAlarmUIDAO.loadAlarmList(keyword, startTimeBucket, endTimeBucket, limit, from);
    List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTimeBucket, endTimeBucket);
    Map<Integer, Integer> mappings = new HashMap<>();
    applicationMappings.forEach(applicationMapping -> mappings.put(applicationMapping.getMappingApplicationId(), applicationMapping.getApplicationId()));
    alarm.getItems().forEach(item -> {
        Instance instance = instanceDAO.getInstance(item.getId());
        String applicationCode = applicationCacheService.getApplicationById(mappings.getOrDefault(instance.getApplicationId(), instance.getApplicationId())).getApplicationCode();
        String serverName = buildServerName(instance.getOsInfo());
        switch(item.getCauseType()) {
            case SLOW_RESPONSE:
                item.setTitle("Server " + serverName + " of Application " + applicationCode + RESPONSE_TIME_ALARM);
                break;
            case LOW_SUCCESS_RATE:
                item.setTitle("Server " + serverName + " of Application  " + applicationCode + SUCCESS_RATE_ALARM);
                break;
        }
    });
    return alarm;
}
Also used : HashMap(java.util.HashMap) Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm)

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