leanIX Metrics Java SDK

SDK for Java to access leanIX Metrics REST API

Лицензия

Лицензия

Категории

Категории

Java Языки программирования Сеть Metrics Тестирование приложения и мониторинг Monitoring
Группа

Группа

net.leanix
Идентификатор

Идентификатор

leanix-metrics-sdk-java
Последняя версия

Последняя версия

0.3.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

leanIX Metrics Java SDK
SDK for Java to access leanIX Metrics REST API
Организация-разработчик

Организация-разработчик

LeanIX GmbH
Система контроля версий

Система контроля версий

https://github.com/leanix/leanix-metrics-sdk-java

Скачать leanix-metrics-sdk-java

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/net.leanix/leanix-metrics-sdk-java/ -->
<dependency>
    <groupId>net.leanix</groupId>
    <artifactId>leanix-metrics-sdk-java</artifactId>
    <version>0.3.2</version>
</dependency>
// https://jarcasting.com/artifacts/net.leanix/leanix-metrics-sdk-java/
implementation 'net.leanix:leanix-metrics-sdk-java:0.3.2'
// https://jarcasting.com/artifacts/net.leanix/leanix-metrics-sdk-java/
implementation ("net.leanix:leanix-metrics-sdk-java:0.3.2")
'net.leanix:leanix-metrics-sdk-java:jar:0.3.2'
<dependency org="net.leanix" name="leanix-metrics-sdk-java" rev="0.3.2">
  <artifact name="leanix-metrics-sdk-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.leanix', module='leanix-metrics-sdk-java', version='0.3.2')
)
libraryDependencies += "net.leanix" % "leanix-metrics-sdk-java" % "0.3.2"
[net.leanix/leanix-metrics-sdk-java "0.3.2"]

Зависимости

compile (11)

Идентификатор библиотеки Тип Версия
io.swagger : swagger-annotations jar 1.5.16
org.glassfish.jersey.core : jersey-client jar
org.glassfish.jersey.media : jersey-media-multipart jar
org.glassfish.jersey.media : jersey-media-json-jackson jar
com.fasterxml.jackson.jaxrs : jackson-jaxrs-base jar
com.fasterxml.jackson.core : jackson-core jar
com.fasterxml.jackson.core : jackson-annotations jar
com.fasterxml.jackson.core : jackson-databind jar
com.fasterxml.jackson.datatype : jackson-datatype-jsr310 jar
com.brsanthu : migbase64 jar 2.2
org.apache.commons : commons-lang3 jar

test (6)

Идентификатор библиотеки Тип Версия
org.slf4j : slf4j-api jar 1.7.24
ch.qos.logback : logback-classic jar 1.2.3
org.slf4j : jcl-over-slf4j jar 1.7.24
org.slf4j : jul-to-slf4j jar 1.7.24
junit : junit jar 4.10
org.assertj : assertj-core jar

Модули Проекта

Данный проект не имеет модулей.

Java SDK for LeanIX metrics REST API

Overview

This SDK contains wrapper code used to call the REST API of the LeanIX metrics service from Java. It allows to create new data points or fetch series from the metrics data store.

Prerequisites

API token

In order to use the code in this SDK, you need an API token to access the metrics service. As a workspace administrator, you can generate a new API token by yourself in the LeanIX application Administration section.

The API token acts as credentials to access a LeanIX workspace as the user who generated the token. Hence you should take care to keep it private, for example by using a password safe application.

The LeanIX REST API uses OAuth2 access tokens to protect its resources. The SDK transparently uses the API token that is set in the ApiClient to obtain such an access token from the token provider. The host name of the token provider is normally "svc.leanix.net".

Swagger documentation

You can find the LeanIX REST API documentation here https://svc.leanix.net/services/metrics/v1/docs/. The documentation is interactive - after entering an API token, you can try out every function directly from the documentation.

How to use?

Including the SDK in your project

Add a dependency to your maven project:

<dependencies>
  <dependency>
    <groupId>net.leanix</groupId>
    <artifactId>leanix-metrics-sdk-java</artifactId>
    <version>0.3.2</version>
  </dependency>
</dependencies>

Writing code

In order to use the SDK in your Java application, import the following packages:

import net.leanix.dropkit.apiclient.*;
import net.leanix.metrics.api.*;
import net.leanix.metrics.api.models.*;

You need to instantiate a LeanIX API Client. The builder class ApiClientBuilder helps you to build the ApiClient with proper configuration.

ApiClient contains a Jersey2 client that does the communication to the server.

An important property of the ApiClient is the URL to the REST API of the MTM service. You also need to provide the API token and the hostname of the token provider here.

ApiClient apiClient = new ApiClientBuilder()
    .withBasePath("https://svc.leanix.net/services/metrics/api/v1")
    .withTokenProviderHost("svc.leanix.net"))
    .withApiToken("NOnrUpMXEh87xbDCYkLfrBmfbzLOFznjqVqEbNMp")
    .build();

PointsApi pointsApi = new PointsApi(apiClient);

You can then use the API class to execute functions.

Examples

We have created some simple examples to show you the main features of the SDK. See example console project.

Create a new data point

See CreatePoint.java

Client client = new ApiClientBuilder()
                .withBasePath("https://svc.leanix.net/services/metrics/v1")
                .withTokenProviderHost("svc.leanix.net")
                .withPersonalAccessToken("my-personal-access-token")
                .build();
PointsApi pointsApi = new PointsApi(client);

// Create a point
Point p1 = new Point();
p1.setMeasurement("CPU");
p1.setWorkspaceId("12345");

// Add a field
Field f1 = new Field();
f1.setK("load");
f1.setV(1.5f);

// Add a tag
Tag t1 = new Tag();
t1.setK("environment");
t1.setV("prod");

p1.getTags().add(t1);
p1.getFields().add(f1);

try {
    pointsApi.createPoint(p1);
    System.out.println("Created point");
} catch (ApiException ex) {
    Logger.getLogger(CreatePoints.class.getName()).log(Level.SEVERE, "Unable to create point", ex);
}

Show results of a series

See ShowSeries.java.

The query language we use is an adaption of influxDB's query language

Client client = new ApiClientBuilder()
                .withBasePath("https://svc.leanix.net/services/metrics/v1")
                .withTokenProviderHost("svc.leanix.net")
                .withPersonalAccessToken("my-personal-access-token");
SeriesApi seriesApi = new SeriesApi(client);

try {
    SeriesResponse response = seriesApi.getSeries("SELECT * FROM CPU", "12345");
    
    System.out.println("Showing data of measurement: " + response.getData().getName());
    
    int index = response.getData().getColumns().indexOf("load");
    
    for (Value v : response.getData().getValues()) {
        System.out.println(v.getT() + ": " + v.getV().get(index));
    }
    
} catch (ApiException ex) {
    Logger.getLogger(ShowSeries.class.getName()).log(Level.SEVERE, null, ex);
}

Known Bugs, Issues and Todos

  • Todo: Allow to submit date when creating a new point
  • Todo: Support creation of more than one point at once (batch)

Building the SDK

To rebuild the SDK, all relevant Swagger API metadata is pulled by default from host svc.leanix.net. This metadata is used to build all Java API classes and models. To specify another host in the pom.xml, use property codegenHost.

mvn clean package -Pcodegen

Copyright and license

Copyright 2016 LeanIX GmbH under the MIT license.

net.leanix

LeanIX GmbH

Версии библиотеки

Версия
0.3.2
0.3.1
0.3.0
0.2.9
0.2.8
0.2.6
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0