Skip to content

UsagePutClient

Joseph Hit Hard edited this page Mar 26, 2020 · 5 revisions

The ApptuitPutClient, included in metrics-apptuit-send-client (and metrics-apptuit-dropwizard), provides a low-level API to upload metrics to Apptuit from Java. The data is compressed with gzip and securely sent over HTTPS by default.

Using this API is recommended only if you already have a framework to collect metrics in your application and are looking for API to report these metrics to Apptuit. For most users, it is highly recommended that you use Dropwizard metrics to instrument your Java code. metrics-apptuit seamlessly integrates with Dropwizard Metrics, to report the metrics to Apptuit.

Aside: JInsight provides a java-agent that extracts a wide array of metrics, from a JVM process - "no coding necessary". If you dig metrics, you will love JInsight!

1. Include maven dependencies

If you are using Maven/Gradle/Ivy, you can get the dependency definition from the metrics-apptuit project on Bintray

Sample snippet for a Maven pom.xml:

<repositories>
  <repository>
    <id>apptuitai-bintray</id>
    <url>https://dl.bintray.com/apptuitai/maven</url>
  </repository>
</repositories>
<dependencies>
  <dependency>
    <groupId>ai.apptuit.metrics</groupId>
    <artifactId>>metrics-apptuit-send-client</artifactId>
    <version>${metrics.apptuit.version}</version>
  </dependency>

2. Create a client

  private static final ApptuitPutClient client = new ApptuitPutClient(APPTUIT_API_KEY, GLOBAL_TAGS_MAP);

APPTUIT_API_KEY is the Access Token for Apptuit
GLOBAL_TAGS_MAP is a Map of tag value pairs (Map<String, String>) that will be applied to all DataPoints. Typically used to add tags like "hostname", "data-center", "environment" etc.

It is highly recommended that you re-use ApptuitPutClient instance to effectively re-use the underlying HTTP connection.

3. Upload DataPoints

    Collection<DataPoint> dataPoints = myDataPoints;
    try {
        client.send(dataPoints);
    } catch (ResponseStatusException rse) {
        //handle exception
    }