/** * Increment the counter for the given statistic. */ public void increment() { increment(false); }
private Builder() { result = new StatusInfo(); }
public static Builder newBuilder() { return new Builder(); }
public StatusInfo getStatusInfo() { StatusInfo.Builder builder = StatusInfo.Builder.newBuilder(); // Add application level status int upReplicasCount = 0; StringBuilder upReplicas = new StringBuilder(); StringBuilder downReplicas = new StringBuilder(); StringBuilder replicaHostNames = new StringBuilder(); for (PeerEurekaNode node : peerEurekaNodes.getPeerEurekaNodes()) { if (replicaHostNames.length() > 0) { replicaHostNames.append(", "); } replicaHostNames.append(node.getServiceUrl()); if (isReplicaAvailable(node.getServiceUrl())) { upReplicas.append(node.getServiceUrl()).append(','); upReplicasCount++; } else { downReplicas.append(node.getServiceUrl()).append(','); } } builder.add("registered-replicas", replicaHostNames.toString()); builder.add("available-replicas", upReplicas.toString()); builder.add("unavailable-replicas", downReplicas.toString()); // Only set the healthy flag if a threshold has been configured. if (peerEurekaNodes.getMinNumberOfAvailablePeers() > -1) { builder.isHealthy(upReplicasCount >= peerEurekaNodes.getMinNumberOfAvailablePeers()); } builder.withInstanceInfo(this.instanceInfo); return builder.build(); }
@Test public void testGetStatusInfoHealthy() { StatusUtil statusUtil = getStatusUtil(3, 3, 2); assertTrue(statusUtil.getStatusInfo().isHealthy()); }
@GET public StatusInfo getStatusInfo() { return statusUtil.getStatusInfo(); }
@Inject StatusResource(EurekaServerContext server) { this.statusUtil = new StatusUtil(server); }
/** * Server context shutdown hook. Override for custom logic */ protected void destroyEurekaServerContext() throws Exception { EurekaMonitors.shutdown(); if (awsBinder != null) { awsBinder.shutdown(); } if (serverContext != null) { serverContext.shutdown(); } }
/** * Servo route; do not call. * * @return servo data */ @com.netflix.servo.annotations.Monitor(name = "numOfRenewsInLastMin", description = "Number of total heartbeats received in the last minute", type = DataSourceType.GAUGE) @Override public long getNumOfRenewsInLastMin() { return renewsLastMin.getCount(); }
protected void postInit() { renewsLastMin.start(); if (evictionTaskRef.get() != null) { evictionTaskRef.get().cancel(); } evictionTaskRef.set(new EvictionTask()); evictionTimer.schedule(evictionTaskRef.get(), serverConfig.getEvictionIntervalTimerInMs(), serverConfig.getEvictionIntervalTimerInMs()); }
/** * Create a new, empty instance registry. */ protected AbstractInstanceRegistry(EurekaServerConfig serverConfig, EurekaClientConfig clientConfig, ServerCodecs serverCodecs) { this.serverConfig = serverConfig; this.clientConfig = clientConfig; this.serverCodecs = serverCodecs; this.recentCanceledQueue = new CircularQueue<Pair<Long, String>>(1000); this.recentRegisteredQueue = new CircularQueue<Pair<Long, String>>(1000); this.renewsLastMin = new MeasuredRate(1000 * 60 * 1); this.deltaRetentionTimer.schedule(getDeltaRetentionTask(), serverConfig.getDeltaRetentionTimerIntervalInMs(), serverConfig.getDeltaRetentionTimerIntervalInMs()); }
/** * Perform all cleanup and shutdown operations. */ @Override public void shutdown() { deltaRetentionTimer.cancel(); evictionTimer.cancel(); renewsLastMin.stop(); }
@Test public void testGetStatusInfoUnhealthy() { StatusUtil statusUtil = getStatusUtil(5, 3, 4); assertFalse(statusUtil.getStatusInfo().isHealthy()); }
private void incrementStats(Target target) { if (serverConfig.isRateLimiterEnabled()) { EurekaMonitors.RATE_LIMITED.increment(); if (target == Target.FullFetch) { EurekaMonitors.RATE_LIMITED_FULL_FETCH.increment(); } } else { EurekaMonitors.RATE_LIMITED_CANDIDATES.increment(); if (target == Target.FullFetch) { EurekaMonitors.RATE_LIMITED_FULL_FETCH_CANDIDATES.increment(); } } }
/** * Gets the number of <em>renewals</em> in the last minute. * * @return a long value representing the number of <em>renewals</em> in the last minute. */ @com.netflix.servo.annotations.Monitor(name = "numOfReplicationsInLastMin", description = "Number of total replications received in the last minute", type = com.netflix.servo.annotations.DataSourceType.GAUGE) public long getNumOfReplicationsInLastMin() { return numberOfReplicationsLastMin.getCount(); }
@Override public void init(PeerEurekaNodes peerEurekaNodes) throws Exception { this.numberOfReplicationsLastMin.start(); this.peerEurekaNodes = peerEurekaNodes; initializedResponseCache(); scheduleRenewalThresholdUpdateTask(); initRemoteRegionRegistry(); try { Monitors.registerObject(this); } catch (Throwable e) { logger.warn("Cannot register the JMX monitor for the InstanceRegistry :", e); } }
@Inject public PeerAwareInstanceRegistryImpl( EurekaServerConfig serverConfig, EurekaClientConfig clientConfig, ServerCodecs serverCodecs, EurekaClient eurekaClient ) { super(serverConfig, clientConfig, serverCodecs); this.eurekaClient = eurekaClient; this.numberOfReplicationsLastMin = new MeasuredRate(1000 * 60 * 1); // We first check if the instance is STARTING or DOWN, then we check explicit overrides, // then we check the status of a potentially existing lease. this.instanceStatusOverrideRule = new FirstMatchWinsCompositeRule(new DownOrStartingRule(), new OverrideExistsRule(overriddenInstanceStatusMap), new LeaseExistsRule()); }
@Test public void testGetStatusInfoUnsetHealth() { StatusUtil statusUtil = getStatusUtil(5, 3, -1); StatusInfo statusInfo = statusUtil.getStatusInfo(); try { statusInfo.isHealthy(); } catch (NullPointerException e) { // Expected that the healthy flag is not set when the minimum value is -1 return; } fail("Excpected NPE to be thrown when healthy threshold is not set"); }