-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #627 from tbak/master
1.x Additional metrics for client side heartbeat/registry staleness monitoring
- Loading branch information
Showing
4 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
eureka-client/src/main/java/com/netflix/discovery/EurekaClientNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2015 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.discovery; | ||
|
||
/** | ||
* @author Tomasz Bak | ||
*/ | ||
public final class EurekaClientNames { | ||
|
||
/** | ||
* Eureka metric names consist of three parts [source].[component].[detailed name]: | ||
* <ul> | ||
* <li>source - fixed to eurekaClient (and eurekaServer on the server side)</li> | ||
* <li>component - Eureka component, like registry cache</li> | ||
* <li>detailed name - a detailed metric name explaining its purpose</li> | ||
* </ul> | ||
*/ | ||
public static final String METRIC_PREFIX = "eurekaClient."; | ||
|
||
public static final String METRIC_REGISTRY_PREFIX = METRIC_PREFIX + "registry."; | ||
|
||
private EurekaClientNames() { | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
eureka-client/src/main/java/com/netflix/discovery/util/ThresholdLevelsMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2015 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.discovery.util; | ||
|
||
import com.netflix.discovery.EurekaClientNames; | ||
import com.netflix.servo.DefaultMonitorRegistry; | ||
import com.netflix.servo.monitor.LongGauge; | ||
import com.netflix.servo.monitor.MonitorConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* A collection of gauges that represent different threshold levels over which measurement is mapped to. | ||
* Value 1 denotes a lowest threshold level that is reached. | ||
* For example eureka client registry data staleness defines thresholds 30s, 60s, 120s, 240s, 480s. Delay of 90s | ||
* would be mapped to gauge values {30s=0, 60s=1, 120=0, 240s=0, 480s=0, unlimited=0}. | ||
* | ||
* @author Tomasz Bak | ||
*/ | ||
public class ThresholdLevelsMetric { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ThresholdLevelsMetric.class); | ||
|
||
private final long[] levels; | ||
private final LongGauge[] gauges; | ||
|
||
public ThresholdLevelsMetric(Object owner, String prefix, long[] levels) { | ||
this.levels = levels; | ||
this.gauges = new LongGauge[levels.length]; | ||
for (int i = 0; i < levels.length; i++) { | ||
String name = EurekaClientNames.METRIC_REGISTRY_PREFIX + prefix + String.format("%05d", levels[i]); | ||
MonitorConfig config = new MonitorConfig.Builder(name) | ||
.withTag("class", owner.getClass().getName()) | ||
.build(); | ||
gauges[i] = new LongGauge(config); | ||
|
||
try { | ||
DefaultMonitorRegistry.getInstance().register(gauges[i]); | ||
} catch (Throwable e) { | ||
logger.warn("Cannot register metric " + name, e); | ||
} | ||
} | ||
} | ||
|
||
public void update(long delayMs) { | ||
long delaySec = delayMs / 1000; | ||
long matchedIdx; | ||
if (levels[0] > delaySec) { | ||
matchedIdx = -1; | ||
} else { | ||
matchedIdx = levels.length - 1; | ||
for (int i = 0; i < levels.length - 1; i++) { | ||
if (levels[i] <= delaySec && delaySec < levels[i + 1]) { | ||
matchedIdx = i; | ||
break; | ||
} | ||
} | ||
} | ||
for (int i = 0; i < levels.length; i++) { | ||
if (i == matchedIdx) { | ||
gauges[i].set(1L); | ||
} else { | ||
gauges[i].set(0L); | ||
} | ||
} | ||
} | ||
|
||
public void shutdown() { | ||
for (LongGauge gauge : gauges) { | ||
try { | ||
DefaultMonitorRegistry.getInstance().unregister(gauge); | ||
} catch (Throwable ignore) { | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters