Skip to content

Commit

Permalink
fix bug: the metrics of caches is lost
Browse files Browse the repository at this point in the history
Change-Id: If99b20ea1d37cbaca8f844d7796b11bb9cfbd601
  • Loading branch information
javeme authored and Linary committed Jan 7, 2019
1 parent 7164a45 commit 55816db
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import com.baidu.hugegraph.task.TaskManager;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.MetricRegistry;

public final class GraphManager {

Expand Down Expand Up @@ -226,15 +225,16 @@ private void addMetrics(HugeConfig config) {
return maxWriteThreads;
});

// Add metrics for cache
// Add metrics for caches
Map<String, Cache> caches = CacheManager.instance().caches();
final AtomicInteger lastCaches = new AtomicInteger(caches.size());
registerCacheMetrics(caches);
final AtomicInteger lastCachesSize = new AtomicInteger(caches.size());
MetricsUtil.registerGauge(Cache.class, "instances", () -> {
int count = caches.size();
if (count != lastCaches.get()) {
registerCacheMetrics();
} else {
lastCaches.set(count);
if (count != lastCachesSize.get()) {
// Update if caches changed (effect in the next report period)
registerCacheMetrics(caches);
lastCachesSize.set(count);
}
return count;
});
Expand All @@ -248,10 +248,8 @@ private void addMetrics(HugeConfig config) {
});
}

private void registerCacheMetrics() {
Map<String, Cache> caches = CacheManager.instance().caches();
final MetricRegistry registry = MetricManager.INSTANCE.getRegistry();
Set<String> names = registry.getNames();
private static void registerCacheMetrics(Map<String, Cache> caches) {
Set<String> names = MetricManager.INSTANCE.getRegistry().getNames();
for (Map.Entry<String, Cache> entry : caches.entrySet()) {
String key = entry.getKey();
Cache cache = entry.getValue();
Expand Down

0 comments on commit 55816db

Please sign in to comment.