Skip to content

Commit

Permalink
Add secondsSinceLastSuccessfulRemoteFetch metric
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmulcahy committed Sep 28, 2020
1 parent 2d61f5f commit 00e827e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -90,6 +93,7 @@ public class RemoteRegionRegistry implements LookupService<String> {
private final EurekaServerConfig serverConfig;
private volatile boolean readyForServingData;
private final EurekaHttpClient eurekaHttpClient;
private long timeOfLastSuccessfulRemoteFetch = System.currentTimeMillis();

@Inject
public RemoteRegionRegistry(EurekaServerConfig serverConfig,
Expand Down Expand Up @@ -240,6 +244,11 @@ private boolean fetchRegistry() {
tracer.stop();
}
}

if (success) {
timeOfLastSuccessfulRemoteFetch = System.currentTimeMillis();
}

return success;
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 00e827e

Please sign in to comment.