Commit 5389b9bd by Madhan Neethiraj Committed by Sarath Subramanian

ATLAS-3147: added periodic logging of stats

parent 0174bac0
......@@ -105,43 +105,50 @@ public class AtlasMetricsCounter {
updateForTime(clock.instant());
}
protected void updateForTime(Instant instant) {
if (instant.isAfter(dayEndTime)) {
rolloverDay(instant);
rolloverHour(instant);
} else if (instant.isAfter(hourEndTime)) {
rolloverHour(instant);
protected void updateForTime(Instant now) {
Instant dayEndTime = this.dayEndTime;
Instant hourEndTime = this.hourEndTime;
if (now.isAfter(dayEndTime)) {
rolloverDay(dayEndTime, now);
rolloverHour(hourEndTime, now);
} else if (now.isAfter(hourEndTime)) {
rolloverHour(hourEndTime, now);
}
}
protected void rolloverDay(Instant instant) {
Instant dayStartTime = getDayStartTime(instant);
protected synchronized void rolloverDay(Instant fromDayEndTime, Instant now) {
if (fromDayEndTime == dayEndTime) { // only if rollover was not done already
Instant dayStartTime = getDayStartTime(now);
if (dayStartTime.equals(dayEndTime)) {
stats.copy(CURR_DAY, PREV_DAY);
} else {
stats.reset(PREV_DAY);
}
if (dayStartTime.equals(dayEndTime)) {
stats.copy(CURR_DAY, PREV_DAY);
} else {
stats.reset(PREV_DAY);
}
stats.reset(CURR_DAY);
stats.reset(CURR_DAY);
this.dayStartTime = dayStartTime;
this.dayEndTime = getNextDayStartTime(instant);
this.dayStartTime = dayStartTime;
this.dayEndTime = getNextDayStartTime(now);
}
}
protected void rolloverHour(Instant instant) {
Instant hourStartTime = getHourStartTime(instant);
protected synchronized void rolloverHour(Instant fromHourEndTime, Instant now) {
if (fromHourEndTime == hourEndTime) { // only if rollover was not done already
Instant hourStartTime = getHourStartTime(now);
if (hourStartTime.equals(hourEndTime)) {
stats.copy(CURR_HOUR, PREV_HOUR);
} else {
stats.reset(PREV_HOUR);
}
if (hourStartTime.equals(hourEndTime)) {
stats.copy(CURR_HOUR, PREV_HOUR);
} else {
stats.reset(PREV_HOUR);
}
stats.reset(CURR_HOUR);
stats.reset(CURR_HOUR);
this.hourStartTime = hourStartTime;
this.hourEndTime = getNextHourStartTime(instant);
this.hourStartTime = hourStartTime;
this.hourEndTime = getNextHourStartTime(now);
}
}
public static LocalDateTime getLocalDateTime(Instant instant) {
......
......@@ -46,6 +46,8 @@ import org.apache.atlas.notification.NotificationInterface.NotificationType;
import org.apache.atlas.notification.preprocessor.EntityPreprocessor;
import org.apache.atlas.notification.preprocessor.PreprocessorContext;
import org.apache.atlas.notification.preprocessor.PreprocessorContext.PreprocessAction;
import org.apache.atlas.util.AtlasMetricsCounter;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.LruCache;
import org.apache.atlas.util.AtlasMetricsUtil;
import org.apache.atlas.util.AtlasMetricsUtil.NotificationStat;
......@@ -78,6 +80,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
......@@ -160,6 +163,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
private final NotificationInterface notificationInterface;
private final Configuration applicationProperties;
private ExecutorService executors;
private Instant nextStatsLogTime = AtlasMetricsCounter.getNextHourStartTime(Instant.now());
@VisibleForTesting
final int consumerRetryInterval;
......@@ -712,6 +716,14 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
AuditFilter.audit(auditLog);
}
Instant now = Instant.now();
if (now.isAfter(nextStatsLogTime)) {
LOG.info("STATS: {}", AtlasJson.toJson(metricsUtil.getStats()));
nextStatsLogTime = AtlasMetricsCounter.getNextHourStartTime(now);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment