/khronus-java-client

Java client for Khronus

Primary LanguageJavaApache License 2.0Apache-2.0

Java client for Khronus

A simple Java client for Khronus.

It works by buffering metrics to send them later in a batch way.

Maven

<dependency>
    <groupId>com.despegar</groupId>
    <artifactId>khronus-java-client</artifactId>
    <version>0.0.2</version>
</dependency>

How to use it

1) Create the client

new KhronusClient.Builder()
          .withApplicationName("exampleApp")
          .withSendIntervalMillis(3000L)
          .withMaximumMeasures(500000)
          .withHosts("KhronusHost:KhronusPort")
          .build()

The application name is prepend to all metrics names, to guarantee uniqueness in Khronus.

The send interval is how often the metrics are sent to Khronus.

Maximum measures is to avoid excessive memory pressure and potentially OOM.

2) Use it to measure a timer

client.recordTime("pageLoad", 300L)

This will push to Khronus a metric named "exampleApp:pageLoad" with a measured value of 300 milliseconds. If the event occurs previously use an overloaded method to pass the specific timestamp.

3) Use it to measure a counter

client.incrementCounter("pageVisits")

Caveats

  1. The send interval should be less or equal than the minor time window configured in Khronus.

  2. Take in care that the client uses an LinkedBlockingQueue in each measure, who has a penalty in concurrency (minor on most usages) for adding a element.