Search in sources :

Example 1 with Event

use of com.creditease.agent.feature.logagent.event.Event in project uavstack by uavorg.

the class ReliableTaildirEventReader method readEvents.

/**
 * @param numEvents
 * @param backoffWithoutNL
 * @param isRollBack
 *            在一些情况下,可能出现多次读取信息,中间不做commit的情况
 * @return
 * @throws IOException
 */
public List<Event> readEvents(int numEvents, boolean backoffWithoutNL, boolean isRollBack) throws IOException {
    if (!this.getCommitted().get() && isRollBack) {
        if (getCurrentFile() == null) {
            throw new IllegalStateException("current file does not exist. " + getCurrentFile().getPath());
        }
        logger.info(this, "Last read was never committed - resetting position");
        long lastPos = getCurrentFile().getPos();
        getCurrentFile().getRaf().seek(lastPos);
    }
    List<Event> events = getCurrentFile().readEvents(numEvents, backoffWithoutNL, addByteOffset);
    if (events.isEmpty()) {
        this.committed.set(false);
        return events;
    }
    Map<String, String> headers = getCurrentFile().getHeaders();
    if (headers != null && !headers.isEmpty()) {
        for (Event event : events) {
            event.getHeaders().putAll(headers);
        }
    }
    this.committed.set(false);
    return events;
}
Also used : Event(com.creditease.agent.feature.logagent.event.Event) NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent)

Example 2 with Event

use of com.creditease.agent.feature.logagent.event.Event 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 3 with Event

use of com.creditease.agent.feature.logagent.event.Event in project uavstack by uavorg.

the class TailFile method readEvents.

public List<Event> readEvents(int numEvents, boolean backoffWithoutNL, boolean addByteOffset) throws IOException {
    List<Event> events = Lists.newLinkedList();
    // Fix:computer the eventSize, if the size overflow Max size, break the numEvents loop
    boolean mutiFlag = TailLogContext.getInstance().getBoolean("MutiThread.enable");
    int readLineNumber = 0;
    int sumEventsLength;
    if (mutiFlag) {
        sumEventsLength = 0;
    } else {
        sumEventsLength = this.getCurrentSumEventsLength();
    }
    for (int i = 0; i < numEvents; i++) {
        Event event = readEvent(backoffWithoutNL, addByteOffset);
        if (event == null) {
            break;
        }
        readLineNumber++;
        sumEventsLength += event.getBodyLength();
        if (sumEventsLength > MaxSize) {
            logger.err(this, "## overflow Max size ### sumEventsLength ###: " + sumEventsLength);
            break;
        }
        events.add(event);
    }
    if (logger.isDebugEnable()) {
        logger.debug(this, "### Before Total LineNo:" + readLineNumber);
    }
    currentSumEventsLength = sumEventsLength;
    return events;
}
Also used : Event(com.creditease.agent.feature.logagent.event.Event)

Aggregations

Event (com.creditease.agent.feature.logagent.event.Event)3 NotificationEvent (com.creditease.agent.monitor.api.NotificationEvent)2 LogAgent (com.creditease.agent.feature.LogAgent)1 LogFilterAndRule (com.creditease.agent.feature.logagent.api.LogFilterAndRule)1 LogPatternInfo (com.creditease.agent.feature.logagent.objects.LogPatternInfo)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Map (java.util.Map)1