Geode 1.9 adopted Micrometer as a way to expose new metrics. Micrometer allows Geode developers measure internal details of Geode in a way that you can publish to a wide variety of external monitoring systems.
Each Geode cache has an internal "meter registry" that collects metrics about the cache and other aspects of the process in which it is running.
Geode's internal meter registry does not itself publish the metrics. It only collects them and makes them available for you to publish. If you want to publish Geode's metrics to an external monitoring system, you must add a "sub-registry" that knows how to publish to that monitoring system.
A "sub-registry" can be any implementation of Micrometer's MeterRegistry class. See the Micrometer documentation for descriptions of the available implementations, and instructions for how to configure them to send information to your monitoring system.
When you add a registry to Geode as a sub-registry, Geode adds all of its current meters to your sub-registry. It also adds any subsequently created meters and keeps your sub-registry informed of all future updates to the values of the meters.
Geode offers two mechanisms to add a meter registry for publishing. Which mechanism you choose depends on how you create the cache.
CacheFactory, you can call the factory's addMeterSubregistry() method one or more times to add sub-registries to the cache it creates.MetricsPublishingService service that initializes your sub-registry and adds it to the cache.Each mechanism is described in detail below.
CacheFactory provides a method to add a 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(...); // Create and configure your registry
Cache cache = new CacheFactory()
.addMeterSubregistry(prometheusRegistry)
.create(); |
You can call this method multiple times to add 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 1.9 and the API may change.
To add a sub-registry to a server or locator:
Each step is described in detail below.
The new interface org.apache.geode.metrics.MetricsPublishingService provides an additional way to publish Geode's Micrometer-based metrics. 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);
}
} |
Package this class into a jar file.
To make your service discoverable, add the following provider-configuration file in the resource directory of your application jar file:
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 1.9 and the API may change.
To add your metrics publishing service to a server or locator, add your jar file to the classpath when you start the server or locator via GFSH:
gfsh>create locator --name my-locator --classpath=<path-to-my-jar-file> gfsh>create server --name my-server --classpath=<path-to-my-jar-file> |
Alternatively, you can add your jar file to the extensions directory in your Geode installation. Then GFSH will add your jar file to the classpath whenever it creates a server or locator.