Micrometer Ganglia

Ganglia is an aging hierarchical metrics system which enjoyed wide popularity in Linux system monitoring and is still in place in many organizations. It originated in the early 2000s at the University of California, Berkeley.

The micrometer-registry-ganglia module uses the gmetric4j library, which contains classes generated by the LGPL licensed remotetea project.

1. Installing micrometer-registry-ganglia

For Gradle, add the following implementation:

implementation 'io.micrometer:micrometer-registry-ganglia:latest.release'

For Maven, add the following dependency:

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-ganglia</artifactId>
  <version>${micrometer.version}</version>
</dependency>

2. Configuring

The following example configures a Ganglia instance:

GangliaConfig gangliaConfig = new GangliaConfig() {
    @Override
    public String host() {
        return "mygraphitehost";
    }

    @Override
    public String get(String k) {
        return null; // accept the rest of the defaults
    }
};

MeterRegistry registry = new GangliaMeterRegistry(gangliaConfig, Clock.SYSTEM);

Micrometer uses Dropwizard Metrics as the underlying instrumentation library when recording metrics destined for Ganglia. GangliaConfig is an interface with a set of default methods. If, in the implementation of get(String k), rather than returning null, you instead bind it to a property source, you can override the default configuration. For example, Micrometer’s Spring Boot support binds properties that are prefixed with management.metrics.export.ganglia directly to the GangliaConfig:

management.metrics.export.ganglia:
    # The location of your Ganglia server
    host: mygraphitehost

    # You will probably want to conditionally disable Ganglia publishing in local development.
    enabled: true

    # The interval at which metrics are sent to Ganglia. The default is 1 minute.
    step: 1m

3. Hierarchical name mapping

Micrometer provides a HierarchicalNameMapper interface that governs how a dimensional meter ID is mapped to flat hierarchical names.

The default (HierarchicalNameMapper.DEFAULT) sorts tags alphabetically by key and appends tag key/value pairs to the base meter name with '.' — for example, http_server_requests.method.GET.response.200. The name and tag keys have the registry’s naming convention applied to them first.

If there is something special about your naming scheme that you need to honor, you can provide your own HierarchicalNameMapper implementation. The most common cause of a custom mapper comes from a need to prefix something to the front of every metric (generally something like app.<name>.http_server_requests.method.GET.response.200).

4. Graphing

This section serves as a quick start to rendering useful representations in Ganglia for metrics originating in Micrometer.

4.1. Counters

Ganglia counters measure mean throughput and one-, five-, and fifteen-minute exponentially-weighted moving average throughputs.

Ganglia-rendered counter
Figure 1. A Ganglia rendered graph of the random walk counter.