Commit 5389b9bd by Madhan Neethiraj Committed by Sarath Subramanian

ATLAS-3147: added periodic logging of stats

parent 0174bac0
...@@ -105,17 +105,21 @@ public class AtlasMetricsCounter { ...@@ -105,17 +105,21 @@ public class AtlasMetricsCounter {
updateForTime(clock.instant()); updateForTime(clock.instant());
} }
protected void updateForTime(Instant instant) { protected void updateForTime(Instant now) {
if (instant.isAfter(dayEndTime)) { Instant dayEndTime = this.dayEndTime;
rolloverDay(instant); Instant hourEndTime = this.hourEndTime;
rolloverHour(instant);
} else if (instant.isAfter(hourEndTime)) { if (now.isAfter(dayEndTime)) {
rolloverHour(instant); rolloverDay(dayEndTime, now);
rolloverHour(hourEndTime, now);
} else if (now.isAfter(hourEndTime)) {
rolloverHour(hourEndTime, now);
} }
} }
protected void rolloverDay(Instant instant) { protected synchronized void rolloverDay(Instant fromDayEndTime, Instant now) {
Instant dayStartTime = getDayStartTime(instant); if (fromDayEndTime == dayEndTime) { // only if rollover was not done already
Instant dayStartTime = getDayStartTime(now);
if (dayStartTime.equals(dayEndTime)) { if (dayStartTime.equals(dayEndTime)) {
stats.copy(CURR_DAY, PREV_DAY); stats.copy(CURR_DAY, PREV_DAY);
...@@ -126,11 +130,13 @@ public class AtlasMetricsCounter { ...@@ -126,11 +130,13 @@ public class AtlasMetricsCounter {
stats.reset(CURR_DAY); stats.reset(CURR_DAY);
this.dayStartTime = dayStartTime; this.dayStartTime = dayStartTime;
this.dayEndTime = getNextDayStartTime(instant); this.dayEndTime = getNextDayStartTime(now);
}
} }
protected void rolloverHour(Instant instant) { protected synchronized void rolloverHour(Instant fromHourEndTime, Instant now) {
Instant hourStartTime = getHourStartTime(instant); if (fromHourEndTime == hourEndTime) { // only if rollover was not done already
Instant hourStartTime = getHourStartTime(now);
if (hourStartTime.equals(hourEndTime)) { if (hourStartTime.equals(hourEndTime)) {
stats.copy(CURR_HOUR, PREV_HOUR); stats.copy(CURR_HOUR, PREV_HOUR);
...@@ -141,7 +147,8 @@ public class AtlasMetricsCounter { ...@@ -141,7 +147,8 @@ public class AtlasMetricsCounter {
stats.reset(CURR_HOUR); stats.reset(CURR_HOUR);
this.hourStartTime = hourStartTime; this.hourStartTime = hourStartTime;
this.hourEndTime = getNextHourStartTime(instant); this.hourEndTime = getNextHourStartTime(now);
}
} }
public static LocalDateTime getLocalDateTime(Instant instant) { public static LocalDateTime getLocalDateTime(Instant instant) {
......
...@@ -46,6 +46,8 @@ import org.apache.atlas.notification.NotificationInterface.NotificationType; ...@@ -46,6 +46,8 @@ import org.apache.atlas.notification.NotificationInterface.NotificationType;
import org.apache.atlas.notification.preprocessor.EntityPreprocessor; import org.apache.atlas.notification.preprocessor.EntityPreprocessor;
import org.apache.atlas.notification.preprocessor.PreprocessorContext; import org.apache.atlas.notification.preprocessor.PreprocessorContext;
import org.apache.atlas.notification.preprocessor.PreprocessorContext.PreprocessAction; 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.utils.LruCache;
import org.apache.atlas.util.AtlasMetricsUtil; import org.apache.atlas.util.AtlasMetricsUtil;
import org.apache.atlas.util.AtlasMetricsUtil.NotificationStat; import org.apache.atlas.util.AtlasMetricsUtil.NotificationStat;
...@@ -78,6 +80,7 @@ import org.springframework.core.annotation.Order; ...@@ -78,6 +80,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.inject.Inject; import javax.inject.Inject;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -160,6 +163,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl ...@@ -160,6 +163,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
private final NotificationInterface notificationInterface; private final NotificationInterface notificationInterface;
private final Configuration applicationProperties; private final Configuration applicationProperties;
private ExecutorService executors; private ExecutorService executors;
private Instant nextStatsLogTime = AtlasMetricsCounter.getNextHourStartTime(Instant.now());
@VisibleForTesting @VisibleForTesting
final int consumerRetryInterval; final int consumerRetryInterval;
...@@ -712,6 +716,14 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl ...@@ -712,6 +716,14 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
AuditFilter.audit(auditLog); 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