Skip to content

How to read Aeron counters programmatically

Problem

You want to feed Aeron Counter data to a metrics system, such as DataDog or Prometheus.

Solution

Read the counter data using CountersReader.

Discussion

The CountersReader is available on the Aeron client or via a CncFileReader.

1
2
3
4
5
6
7
8
final CountersReader counters = aeron.countersReader();

counters.forEach(
    (counterId, typeId, keyBuffer, label) ->
    {
        //this is all available Counter data
    }
);

Notes:

  • If you're writing into something with a blocking API, it may be beneficial to run this within a dedicated agent that runs on a relatively slow schedule (for example once a second)
  • Using the CncFileReader allows you to read Aeron counter data from an external process. See the AeronStat source code (link below) for an example on how to do this.
  • Avoid reading this data if the Aeron client is closed.

See Also