diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java b/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java index 485e38ec7..242fccf87 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java @@ -52,6 +52,7 @@ import com.netflix.eureka.EurekaServerIdentity; import com.netflix.eureka.resources.ServerCodecs; import com.netflix.eureka.transport.EurekaServerHttpClients; +import com.netflix.servo.annotations.DataSourceType; import com.netflix.servo.monitor.Monitors; import com.netflix.servo.monitor.Stopwatch; import com.sun.jersey.api.client.ClientResponse; @@ -60,6 +61,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static com.netflix.eureka.Names.METRIC_REGISTRY_PREFIX; + /** * Handles all registry operations that needs to be done on a eureka service running in an other region. * @@ -90,6 +93,7 @@ public class RemoteRegionRegistry implements LookupService { private final EurekaServerConfig serverConfig; private volatile boolean readyForServingData; private final EurekaHttpClient eurekaHttpClient; + private long timeOfLastSuccessfulRemoteFetch = System.currentTimeMillis(); @Inject public RemoteRegionRegistry(EurekaServerConfig serverConfig, @@ -240,6 +244,11 @@ private boolean fetchRegistry() { tracer.stop(); } } + + if (success) { + timeOfLastSuccessfulRemoteFetch = System.currentTimeMillis(); + } + return success; } @@ -501,4 +510,9 @@ private boolean shouldUseExperimentalTransport() { String enabled = serverConfig.getExperimental("transport.enabled"); return enabled != null && "true".equalsIgnoreCase(enabled); } + + @com.netflix.servo.annotations.Monitor(name = METRIC_REGISTRY_PREFIX + "secondsSinceLastSuccessfulRemoteFetch", type = DataSourceType.GAUGE) + public long getTimeOfLastSuccessfulRemoteFetch() { + return (System.currentTimeMillis() - timeOfLastSuccessfulRemoteFetch) / 1000; + } }