caching - 在 Spring Data Geode 客户端应用程序中获取区域统计信息
问题描述
我需要获取有关 apache geode 客户端缓存应用程序的区域统计信息。
设置:1 个定位器 1 个服务器 1 个客户端缓存应用程序
所有模块都是使用spring创建的。
缓存服务器将根据cache.xml创建区域
缓存.xml:
<?xml version="1.0" encoding="UTF-8"?>
<cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://geode.apache.org/schema/cache"
xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
version="1.0" lock-lease="120" lock-timeout="60" search-timeout="300"
is-server="true" copy-on-read="false">
<pdx read-serialized="true" persistent="true">
<pdx-serializer>
<class-name>
org.apache.geode.pdx.ReflectionBasedAutoSerializer
</class-name>
</pdx-serializer>
</pdx>
<region name="track" refid="PARTITION_PERSISTENT_OVERFLOW">
<region-attributes statistics-enabled="true">
<compressor>
<class-name>org.apache.geode.compression.SnappyCompressor</class-name>
</compressor>
</region-attributes>
<index name="trackKeyIndex" from-clause="/track" expression="key" key-index="true"/>
<index name="trackTransactionNameIndex" from-clause="/track" expression="transactions[*]"/>
</region>
</cache>
缓存服务器应用程序
@SpringBootApplication
@org.springframework.data.gemfire.config.annotation.CacheServerApplication(name = "cacheServer", locators = "localhost[10334]")
@EnableClusterAware
@EnableCompression
@EnableStatistics
@EnableGemFireProperties(cacheXmlFile = "cache.xml")
public class CacheServerApplication {
public static void main(String[] args) {
SpringApplication.run(CacheServerApplication.class, args);
}
}
客户端缓存应用程序
@SpringBootApplication
@ClientCacheApplication
@EnableClusterDefinedRegions //Fetch cluster defined regions for @Resource autowired prop
@EnableStatistics
public class GeodeClientApplication {
public static void main(String[] args) {
SpringApplication.run(GeodeClientApplication.class, args);
}
}
客户端缓存中的组件类,用于获取区域统计信息。
@Component
public class TrackedInsightsCacheService {
private static Logger logger = LoggerFactory.getLogger(TrackedInsightsCacheService.class);
@Autowired
@Resource(name = "track")
private Region trackRegion;
public Object getRegionStatistics(){
RegionAttributes attributes = trackRegion.getAttributes();
if(attributes.getStatisticsEnabled()) {
return trackRegion.getStatistics();
}
return null;
}
public Object get(String key) {
return trackRegion.get(key);
}
public void put(String key, String value){
trackRegion.put(key, value);
}
}
Autowired TrackRegion 是 LocalRegion。每当我进行 get 调用时,它首先检查本地区域,然后检查服务器区域上的密钥。
但是当我调用 getStatistics 时,它说该地区的统计信息已禁用。
我在这里想念什么?这是获取区域统计信息的正确方法吗?
我可以通过 gfsh 命令行获取集群统计信息,输出是这样的,
gfsh>show metrics
Cluster-wide Metrics
Category | Metric | Value
--------- | --------------------- | -----
cluster | totalHeapSize | 4846
cache | totalRegionEntryCount | 1
| totalRegionCount | 1
| totalMissCount | 81
| totalHitCount | 15
diskstore | totalDiskUsage | 0
| diskReadsRate | 0.0
| diskWritesRate | 0.0
| flushTimeAvgLatency | 0
| totalBackupInProgress | 0
query | activeCQCount | 0
| queryRequestRate | 0.0
我在设置中有多个区域,仅查看集群统计数据是不够的,因此要寻找获取区域度量数据。
解决方案
该getStatistics()
方法返回实际Region
实例的统计信息。由于您在客户端执行此方法,因此返回的实际统计信息将用于本地客户端Region
,这不是您想要的。
该gfsh show metrics
命令实际上使用检索区域统计信息,您可以在此处JMX
查看源代码并根据需要对其进行调整。
如果您不想使用JMX
,另一种选择是编写自定义Geode 函数并通过使用StatisticsManager手动检索您正在查找的统计信息。
干杯。
推荐阅读
- ios - 如何在 SwiftUI 中以编程方式在屏幕的某些部分模拟点击/滑动手势?
- sql - 合并来自多个表的值而不重复它
- java - 整数 - 错误:“.class”预期,“;” 预期而不是陈述
- c++ - 输入行大小超过 256 个字符时,getline/fgets 表现得很奇怪
- django - query set lost when page changes in Django
- matlab - 意外的数组长度并导致绘图错误
- visual-studio-code - 如何在 Visual Studio Code 中设置默认的 jupyter notebook 编辑器?
- jmeter - 如何在运行时将变量传递给graphql请求
- python-3.x - 在 tkinter 中添加线条颜色
- python - 表示不变量的简单解释