Search in sources :

Example 1 with DiyMonitorGroup

use of info.xiancloud.core.support.falcon.DiyMonitorGroup in project xian by happyyangyuan.

the class FactorCollector method collect.

public static JSONObject collect() {
    JSONObject factorOriented = new JSONObject();
    String diyMonitorServiceName = new DiyMonitorGroup().getName();
    Set<String> diyMonitorUnitNames = new HashSet<>();
    try {
        for (GroupInstance serviceInstance : GroupRouter.singleton.allInstances(diyMonitorServiceName)) {
            diyMonitorUnitNames.addAll(serviceInstance.getPayload().getUnitNames());
        }
    } catch (GroupOfflineException | GroupUndefinedException e) {
        throw new RuntimeException(e);
    }
    for (String diyMonitorUnitName : diyMonitorUnitNames) {
        UnitResponse o = SyncXian.call(diyMonitorServiceName, diyMonitorUnitName, new HashMap());
        if (o.succeeded()) {
            try {
                LOG.debug("data可以是单纯的数字,也可以是json/jsonArray");
                factorOriented.put(diyMonitorUnitName, o.getData());
            } catch (Throwable e) {
                LOG.error("收集指标 '" + diyMonitorUnitName + "' 时出现异常,返回-1作为指标值", e);
                factorOriented.put(diyMonitorUnitName, ERROR_VALUE_NEGATIVE_1);
            }
        } else {
            LOG.error("收集指标 '" + diyMonitorUnitName + "' 失败 !  返回-1作为指标值   .   失败内容为 :" + o);
            factorOriented.put(diyMonitorUnitName, ERROR_VALUE_NEGATIVE_1);
        }
    }
    return factorOriented;
}
Also used : HashMap(java.util.HashMap) GroupOfflineException(info.xiancloud.core.distribution.exception.GroupOfflineException) GroupUndefinedException(info.xiancloud.core.distribution.exception.GroupUndefinedException) DiyMonitorGroup(info.xiancloud.core.support.falcon.DiyMonitorGroup) JSONObject(com.alibaba.fastjson.JSONObject) UnitResponse(info.xiancloud.core.message.UnitResponse) GroupInstance(info.xiancloud.core.distribution.service_discovery.GroupInstance) HashSet(java.util.HashSet)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 GroupOfflineException (info.xiancloud.core.distribution.exception.GroupOfflineException)1 GroupUndefinedException (info.xiancloud.core.distribution.exception.GroupUndefinedException)1 GroupInstance (info.xiancloud.core.distribution.service_discovery.GroupInstance)1 UnitResponse (info.xiancloud.core.message.UnitResponse)1 DiyMonitorGroup (info.xiancloud.core.support.falcon.DiyMonitorGroup)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1