-
Notifications
You must be signed in to change notification settings - Fork 10
UsagePrometheusClient
Rajiv edited this page Oct 31, 2019
·
2 revisions
The PrometheusClient
, included in metrics-apptuit-prometheus-client, provides Java API to query metrics from Apptuit using Prometheus Query language.
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-prometheus-client</artifactId>
<version>${metrics.apptuit.version}</version>
</dependency>
private static final PrometheusClient client = new PrometheusClient(APPTUIT_API_KEY);
APPTUIT_API_KEY
is the Access Token for Apptuit
It is highly recommended that you re-use PrometheusClient
instance to effectively re-use the underlying HTTP connection.
QueryResponse response = client.query(System.currentTimeMillis()-300000, System.currentTimeMillis(), "node_cpu_used_percent{env='prd'}";
if (response.getStatus() == AbstractResponse.STATUS.error) {
System.err.println("ERROR [" + response.getErrorType() + "]: " + response.getError());
} else {
List<String> warnings = response.getWarnings();
if (warnings.size() > 0) {
System.err.println("WARNINGS: " + warnings);
}
for (TimeSeries series : ((MatrixResult) response.getResult()).getSeries()) {
System.out.println("Series: " + series.getLabels());
for (TimeSeries.Tuple dataPoint : series.getValues()) {
System.out.println(dataPoint.getTimestamp() + ":" + dataPoint.getValue());
}
}
}