You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Geode now uses Micrometer for exposing metrics. Under the covers, Geode uses a CompositeMeterRegistry which may publish out to any number of monitoring systems. See the Micrometer documentation.

Users can choose between two different approaches for plugging in a monitoring system with a MeterRegistry:

  • CacheFactory.addMeterSubregistry(MeterRegistry)
  • ServiceLoader implementations of MetricsPublishingService

Adding Meter Registries when Creating a Cache

CacheFactory provides a new method which adds the given meter registry to the cache's composite registry for publishing cache metrics to external monitoring systems:

public CacheFactory addMeterSubregistry(MeterRegistry subregistry);

Example adding a meter sub-registry:

MeterRegistry prometheusRegistry = new PrometheusMeterRegistry(...);

Cache cache = new CacheFactory()
    .addMeterSubregistry(prometheusRegistry)
    .create();

Example adding multiple meter sub-registries:

MeterRegistry prometheusRegistry = new PrometheusMeterRegistry(...);
MeterRegistry influxRegistry = new InfluxMeterRegistry(...);
MeterRegistry newRelicRegistry = new NewRelicMeterRegistry(...);

Cache cache = new CacheFactory()
    .addMeterSubregistry(prometheusRegistry)
    .addMeterSubregistry(influxRegistry)
    .addMeterSubregistry(newRelicRegistry)
    .create();

Note: The above APIs are considered experimental. Micrometer metrics is a new addition to Geode and the API may change.

Adding Meter Registries using the ServiceLoader

The new interface org.apache.geode.metrics.MetricsPublishingService provides an additional way to publish metrics generated by Micrometer meters in the cache meter registry. Geode discovers implementations of MetricsPublishingService during cache creation, using the standard Java ServiceLoader mechanism.

Example implementation of MetricsPublishingService:

package com.application;

public class MyMetricsPublishingService implements MetricsPublishingService {
    private volatile MeterRegistry registry;
    private volatile MetricsSession session;

    @Override
    public void start(MetricsSession session) {
        this.session = session;
        registry = ... // configure your meter registry and start publishing

        // add your registry as a sub-registry to the cache's composite registry
        session.addSubregistry(registry);
    }

    @Override
    public void stop() {
        ...
        // clean up any resources used by your meter registry
        ...

        session.removeSubregistry(registry);
    }
}

To make your service available for loading, add the following provider-configuration file in the resource directory of your application Jar:

META-INF/services/org.apache.geode.metrics.MetricsPublishingService

Add a line inside the file indicating the fully qualified class name of your implementation:

com.application.MyMetricsPublishingService

Note: The above APIs are considered experimental. Micrometer metrics is a new addition to Geode and the API may change.

  • No labels