Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

caching - Get region statistics in spring data geode client application

I need to get the region statistics on apache geode client-cache application.

Setup: 1 locator 1 server 1 client-cache app

All the modules are created using spring.

Cache server will create regions based on the cache.xml

Cache.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>

Cache-server application

@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);
    }
}

Client-cache application

@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 class in client-cache to fetch region statistics.

@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 is LocalRegion. Whenever I do a get call, it first checks the local region then checks the key on server region.

But When I do the getStatistics call, it says statistics are disabled for the region.

What am I missing here? Is this the proper way to get region statistics.

I'm able to get the cluster statistics through the gfsh command line and output is something like this,

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

I have multiple regions in the setup and looking at the cluster wise statistics is not sufficient, so looking for getting region-wise metrics data.

question from:https://stackoverflow.com/questions/65951749/get-region-statistics-in-spring-data-geode-client-application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The getStatistics() method returns the statistics for the actual Region instance. Since you're executing this method on the client side, the actual statistics returned will be for the local client Region, which is not what you want.

The gfsh show metrics command actually retrieves the region statistics using JMX, you could check the source code and adapt it to your needs here.

Another option, if you don't want to use JMX, would be to write a custom Geode Function and manually retrieve the statistics you're looking for through the usage of the StatisticsManager.

Cheers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...