[英]Spring boot cache Hazelcast return empty list of cache names and no metrics will display
我开始使用 Hazelcast 缓存,我想为它们公开指标,但我不知道该怎么做。
我的java配置
`@Configuration 公共类 HazelcastConfiguration {
@Bean
public Config config(){
return new Config()
.setInstanceName("hazelcast-instace")
.addMapConfig(
new MapConfig()
.setName("testing")
.setMaxSizeConfig(new MaxSizeConfig(10, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE))
.setEvictionPolicy(EvictionPolicy.LRU)
.setTimeToLiveSeconds(1000)
.setStatisticsEnabled(true)
);
}
}`
在启动应用程序期间,我只看到此日志
2019-11-30 19:56:01.579 INFO 13444 --- [ main] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.4] Prefer IPv4 stack is true, prefer IPv6 addresses is false
2019-11-30 19:56:01.671 INFO 13444 --- [ main] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.4] Picked [192.168.43.2]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
2019-11-30 19:56:01.694 INFO 13444 --- [ main] com.hazelcast.system : [192.168.43.2]:5701 [dev] [3.12.4] Hazelcast 3.12.4 (20191030 - eab1290) starting at [192.168.43.2]:5701
2019-11-30 19:56:01.695 INFO 13444 --- [ main] com.hazelcast.system : [192.168.43.2]:5701 [dev] [3.12.4] Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
2019-11-30 19:56:02.037 INFO 13444 --- [ main] c.h.s.i.o.impl.BackpressureRegulator : [192.168.43.2]:5701 [dev] [3.12.4] Backpressure is disabled
2019-11-30 19:56:02.761 INFO 13444 --- [ main] com.hazelcast.instance.Node : [192.168.43.2]:5701 [dev] [3.12.4] Creating MulticastJoiner
2019-11-30 19:56:02.998 INFO 13444 --- [ main] c.h.s.i.o.impl.OperationExecutorImpl : [192.168.43.2]:5701 [dev] [3.12.4] Starting 4 partition threads and 3 generic threads (1 dedicated for priority tasks)
2019-11-30 19:56:02.999 INFO 13444 --- [ main] c.h.internal.diagnostics.Diagnostics : [192.168.43.2]:5701 [dev] [3.12.4] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2019-11-30 19:56:03.007 INFO 13444 --- [ main] com.hazelcast.core.LifecycleService : [192.168.43.2]:5701 [dev] [3.12.4] [192.168.43.2]:5701 is STARTING
2019-11-30 19:56:05.085 INFO 13444 --- [ main] c.h.internal.cluster.ClusterService : [192.168.43.2]:5701 [dev] [3.12.4]
Members {size:1, ver:1} [
Member [192.168.43.2]:5701 - 6ed511ff-b20b-4875-9b39-2dc734d4a9aa this
]
2019-11-30 19:56:05.142 INFO 13444 --- [ main] com.hazelcast.core.LifecycleService : [192.168.43.2]:5701 [dev] [3.12.4] [192.168.43.2]:5701 is STARTED
2019-11-30 19:56:05.295 INFO 13444 --- [e.HealthMonitor] c.h.internal.diagnostics.HealthMonitor : [192.168.43.2]:5701 [dev] [3.12.4] processors=4, physical.memory.total=23,9G, physical.memory.free=11,8G, swap.space.total=27,2G, swap.space.free=10,3G, heap.memory.used=306,9M, heap.memory.free=357,1M, heap.memory.total=664,0M, heap.memory.max=5,3G, heap.memory.used/total=46,23%, heap.memory.used/max=5,63%, minor.gc.count=0, minor.gc.time=0ms, major.gc.count=0, major.gc.time=0ms, load.process=100,00%, load.system=100,00%, load.systemAverage=n/a thread.count=37, thread.peakCount=37, cluster.timeDiff=0, event.q.size=0, executor.q.async.size=0, executor.q.client.size=0, executor.q.client.query.size=0, executor.q.client.blocking.size=0, executor.q.query.size=0, executor.q.scheduled.size=0, executor.q.io.size=0, executor.q.system.size=0, executor.q.operations.size=0, executor.q.priorityOperation.size=0, operations.completed.count=1, executor.q.mapLoad.size=0, executor.q.mapLoadAllKeys.size=0, executor.q.cluster.size=0, executor.q.response.size=0, operations.running.count=0, operations.pending.invocations.percentage=0,00%, operations.pending.invocations.count=0, proxy.count=0, clientEndpoint.count=0, connection.active.count=0, client.connection.count=0, connection.count=0
在自动装配类 CacheManager I 并在其上运行函数 getCacheNames 之后,我看到一个空列表,我不知道为什么?
并在第一次添加到缓存中时在日志中显示
2019-11-30 20:11:12.760 INFO 16464 --- [nio-8080-exec-6] c.h.i.p.impl.PartitionStateManager : [192.168.43.2]:5701 [dev] [3.12.4] Initializing cluster partition table arrangement...
在 Metrics Config 文件中,我有这个,但 metrics 中的任何内容都不会显示:
@Autowired
private CacheMetricsRegistrar cacheMetricsRegistrar;
任何人都知道为什么它不起作用?
当您将第一个条目插入其中时,缓存将被初始化。 这就是为什么您一开始在CacheManager
中看不到任何缓存的原因。 插入第一个值后,您应该会在cacheManager.caches
HazelcastCache
与CacheMetricsRegistrar
相同,我只是尝试在binderProviders
HazelcastCacheMeterBinderProvider
对于 Spring Boot 2.x,创建您的注册组件:
@Component
@AllArgsConstructor
public class CacheMetricsRegistrator {
private final CacheMetricsRegistrar cacheMetricsRegistrar;
private final CacheManager cacheManager;
private final Config cacheConfig;
@PostConstruct
public void register() {
this.cacheConfig.getMapConfigs().keySet().forEach(
cacheName -> this.cacheMetricsRegistrar.bindCacheToRegistry(
this.cacheManager.getCache(cacheName))
);
}
}
对于 Hazelcast 的缓存配置:
@EnableCaching
@Configuration
public class HazelcastConfig {
private MapConfig mapPortfolioCache() {
return new MapConfig()
.setName("my-entity-cache")
.setEvictionConfig(new EvictionConfig().setMaxSizePolicy(MaxSizePolicy.FREE_HEAP_SIZE).setSize(200))
.setTimeToLiveSeconds(60*15);
}
@Bean
public Config hazelCastConfig() {
Config config = new Config()
.setInstanceName("my-application-hazelcast")
.setNetworkConfig(new NetworkConfig().setJoin(new JoinConfig().setMulticastConfig(new MulticastConfig().setEnabled(false))))
.addMapConfig(mapPortfolioCache());
SubZero.useAsGlobalSerializer(config);
return config;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.