Search in sources :

Example 6 with NotificationEvent

use of com.creditease.agent.monitor.api.NotificationEvent in project uavstack by uavorg.

the class TaildirLogComponent method tailFileCommon.

@SuppressWarnings("rawtypes")
public void tailFileCommon(TailFile tf, boolean backoffWithoutNL, Map<TailFile, List<Map>> serverlogs) throws IOException, InterruptedException {
    long current = System.currentTimeMillis();
    boolean isEvents = false;
    // while (true) {
    reader.setCurrentFile(tf);
    List<Event> events = reader.readEvents(batchSize, backoffWithoutNL);
    if (!events.isEmpty()) {
        isEvents = true;
    }
    try {
        LogFilterAndRule main = RuleFilterFactory.getInstance().getLogFilterAndRule(tf.getPath());
        List<LogFilterAndRule> aids = RuleFilterFactory.getInstance().getAidLogFilterAndRuleList(tf.getPath());
        List<Map> datalog = RuleFilterFactory.getInstance().createChain(reader, batchSize).setMainLogFilterAndRule(main).setAidLogFilterAndRuleList(aids).doProcess(events, backoffWithoutNL);
        if (!datalog.isEmpty()) {
            if (serverlogs.containsKey(tf)) {
                serverlogs.get(tf).addAll(datalog);
            } else
                serverlogs.put(tf, datalog);
        }
        reader.commit(events.size() < batchSize);
    } catch (IOException ex) {
        log.warn(this, "The unexpected failure. " + "The source will try again after " + retryInterval + " ms");
    // TimeUnit.MILLISECONDS.sleep(retryInterval);
    // retryInterval = retryInterval << 1;
    // retryInter val = Math.min(retryInterval, maxRetryInterval);
    // continue;
    }
    // retryInterval = 1000;
    // if (events.size() < batchSize) {
    // break;
    // }
    // }
    // renew
    LogAgent logagent = (LogAgent) ConfigurationManager.getInstance().getComponent("logagent", "LogAgent");
    LogPatternInfo info = logagent.getLatestLogProfileDataMap().get(tf.getServerId() + "-" + tf.getAppId(), tf.getId());
    if (info != null && isEvents) {
        info.setTimeStamp(current);
        LogPatternInfo innerInfo = reader.getTailFileTable().asMap().get(info.getAbsolutePath());
        if (innerInfo != null) {
            innerInfo.setTimeStamp(current);
            // FIXME concurrent problem
            reader.getTailFileTable().put(innerInfo.getAbsolutePath(), innerInfo);
        }
    }
    if (info != null && current - info.getTimeStamp() > timeOutInterval) {
        logagent.getLatestLogProfileDataMap().remove(tf.getServerId() + "-" + tf.getAppId(), tf.getId());
        // notify
        String title = NetworkHelper.getLocalIP() + "日志[" + tf.getId() + "]的过滤规则配置已经过期.";
        log.err(this, title);
        NotificationEvent event = new NotificationEvent(NotificationEvent.EVENT_LogRuleExpired, title, title);
        event.addArg("serverid", tf.getServerId());
        event.addArg("appid", tf.getAppId());
        this.putNotificationEvent(event);
    }
}
Also used : NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent) IOException(java.io.IOException) LogFilterAndRule(com.creditease.agent.feature.logagent.api.LogFilterAndRule) LogAgent(com.creditease.agent.feature.LogAgent) Event(com.creditease.agent.feature.logagent.event.Event) NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent) LogPatternInfo(com.creditease.agent.feature.logagent.objects.LogPatternInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with NotificationEvent

use of com.creditease.agent.monitor.api.NotificationEvent in project uavstack by uavorg.

the class BaseMonitorDataCatchWorker method doHealthReaction.

protected void doHealthReaction() {
    String title = null;
    String content = null;
    // check if appserver is dead
    if (isVMAlive(this.appServerInfo) == true) {
        title = NetworkHelper.getLocalIP() + this.getProcessInfoName() + "仍然运行中,但监测数据采集连接失败.";
        content = "失败原因:1)该应用进程实例没有安装UAV监控捕获框架。2)可能由于应用容器(物理机或虚机)IP地址变化。3)可能当前的捕获连接[" + this.appServerInfo.getJVMAccessURL().toString() + "]失效。";
    } else {
        title = NetworkHelper.getLocalIP() + this.getProcessInfoName() + "已经死掉,不能进行数据采集.";
        content = "该进程已经死掉。";
    }
    // step 1: stop catch timer
    detector.removeWorker(this.cName);
    // step 2: notify
    NotificationEvent event = new NotificationEvent(NotificationEvent.EVENT_ReAccessFAIL, title, content);
    event.addArg("serverid", this.getWorkerId());
    this.putNotificationEvent(event);
    log.err(this, title);
}
Also used : NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent)

Example 8 with NotificationEvent

use of com.creditease.agent.monitor.api.NotificationEvent in project uavstack by uavorg.

the class NotificaitonScheduleWorker method executencTestcase.

public void executencTestcase(String testcaseNumber) {
    log.info(this, "executeNCTestcase:" + testcaseNumber);
    String jsonString = prepareTestData(testcaseNumber);
    NotificationEvent event = new NotificationEvent(jsonString);
    log.info(this, "jsonStr:" + event.toJSONString());
    this.putNotificationEvent(event);
}
Also used : NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent)

Example 9 with NotificationEvent

use of com.creditease.agent.monitor.api.NotificationEvent in project uavstack by uavorg.

the class NotifyDataAdpater method prepareInsertObj.

@Override
public Object prepareInsertObj(DataStoreMsg msg, DataStoreConnection NotifyDataAdpaterconnection) {
    List<Map<String, Object>> documents = new ArrayList<Map<String, Object>>();
    /**
     * 消息message传输过来的NTFEVENT是一个列表包含多个NTFEVENT的json字符串
     */
    // parse NTFEVENT list
    String ntfListStr = (String) msg.get(MonitorDataFrame.MessageType.Notification.toString());
    List<String> ntfList = JSONHelper.toObjectArray(ntfListStr, String.class);
    for (String ntfStr : ntfList) {
        NotificationEvent ne = new NotificationEvent(ntfStr);
        Map<String, Object> document = new LinkedHashMap<String, Object>();
        // add4NotificationCenter usage: bug fix , before encode value of Event, should not change the code line
        document.put("ntfkey", DataStoreHelper.encodeForMongoDB(getKeyfromNTFE(ne)));
        document.put("firstrecord", "false");
        Map<String, String> args = new LinkedHashMap<String, String>();
        Map<String, String> argsDecode = ne.getArgs(true);
        for (String key : ne.getArgs(false).keySet()) {
            args.put(DataStoreHelper.encodeForMongoDB(key), argsDecode.get(key));
        }
        document.put("args", args);
        document.put("eventid", ne.getId());
        document.put("title", ne.getTitle());
        document.put("description", ne.getDescription());
        document.put("time", ne.getTime());
        document.put("host", ne.getHost());
        document.put("ip", ne.getIP());
        document.put("appgroup", args.get("appgroup"));
        document.put("createtime", System.currentTimeMillis());
        document.put("notifyType", getNotifyType(ne.getTitle()));
        documents.add(document);
    }
    return documents;
}
Also used : ArrayList(java.util.ArrayList) NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with NotificationEvent

use of com.creditease.agent.monitor.api.NotificationEvent in project uavstack by uavorg.

the class JudgeNotifyTimerTask method newNotificationEvent.

/**
 * newNotificationEvent
 *
 * @return
 */
private NotificationEvent newNotificationEvent(String instance, Map<String, String> result, List<String> convergences) {
    String ip = instance;
    String host = instance;
    String appgroup = "UNKNOWN";
    instance = formatInstance(instance);
    Map<String, Object> infos = getInfoFromSliceCache(instance);
    if (infos != null) {
        ip = String.valueOf(infos.get("ip"));
        host = String.valueOf(infos.get("host"));
        appgroup = String.valueOf(infos.get("appgroup"));
    }
    StringBuilder desc = new StringBuilder();
    List<String> conditionIndex = new ArrayList<String>();
    for (Map.Entry<String, String> cause : result.entrySet()) {
        // description
        desc.append(instance + "触发条件[" + cause.getKey() + "]:").append(cause.getValue()).append("\r\n");
        // condition index
        conditionIndex.add(cause.getKey());
    }
    String title = ip + "[" + instance + "]触发" + result.size() + "个报警(条件序号: " + conditionIndex.toString().replaceAll("\\[|]|,", "") + ")";
    // fix &nbsp(\u00A0) can be shown in email
    String description = desc.toString().replace('\u00A0', ' ');
    NotificationEvent ne = new NotificationEvent(NotificationEvent.EVENT_RT_ALERT_THRESHOLD, title, description, judge_time, ip, host);
    // add appgroup
    ne.addArg("appgroup", appgroup);
    // 兼容不存在convergences属性的旧预警策略
    if (convergences == null || convergences.size() == 0) {
        return ne;
    }
    // 同一个Event由多个策略触发时,梯度收敛以最长的为准
    String conv = obtainConvergenceForEvent(convergences, conditionIndex);
    if (!StringHelper.isEmpty(conv)) {
        ne.addArg("convergences", conv);
        ne.addArg(NotificationEvent.EVENT_Tag_NoBlock, "true");
    }
    return ne;
}
Also used : ArrayList(java.util.ArrayList) NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent) Map(java.util.Map)

Aggregations

NotificationEvent (com.creditease.agent.monitor.api.NotificationEvent)19 Map (java.util.Map)6 LogPatternInfo (com.creditease.agent.feature.logagent.objects.LogPatternInfo)4 ArrayList (java.util.ArrayList)4 LogAgent (com.creditease.agent.feature.LogAgent)3 LinkedHashMap (java.util.LinkedHashMap)3 NotifyStrategy (com.creditease.uav.feature.runtimenotify.NotifyStrategy)2 Slice (com.creditease.uav.feature.runtimenotify.Slice)2 StrategyJudgement (com.creditease.uav.feature.runtimenotify.StrategyJudgement)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ConfigurationContext (com.creditease.agent.ConfigurationContext)1 NotificationCenter (com.creditease.agent.feature.NotificationCenter)1 GlobalNotificationManager (com.creditease.agent.feature.globalnotify.GlobalNotificationManager)1 TaildirLogComponent (com.creditease.agent.feature.logagent.TaildirLogComponent)1 LogFilterAndRule (com.creditease.agent.feature.logagent.api.LogFilterAndRule)1 Event (com.creditease.agent.feature.logagent.event.Event)1 NCJudgementWorker (com.creditease.agent.feature.notifycenter.NCJudgementWorker)1 PersistentTask (com.creditease.agent.feature.notifycenter.task.PersistentTask)1