A java client for the Prometheus REST API.
implementation("io.github.primelib:prometheus4j:<latestVersion>")
Click to view instructions for other build tools.
Consumer Specification Approach
PrometheusHTTPConsumerApi client = PrometheusHTTPFactory.create(spec -> {
spec.api(PrometheusHTTPConsumerApi.class);
spec.baseUrl("http://localhost:9090/api/v1");
// optional auth
spec.basicAuth(authSpec -> {
authSpec.username("<username>");
authSpec.password("<password>");
});
});
RuleReadResponse alertingRules = client.readRules(spec ->{
spec.type("alert")
});
Parameter Approach
PrometheusHTTPApi client = PrometheusHTTPFactory.create(spec -> {
spec.api(PrometheusHTTPApi.class);
spec.baseUrl("http://localhost:9090/api/v1");
// optional auth
spec.basicAuth(authSpec -> {
authSpec.username("<username>");
authSpec.password("<password>");
});
});
RuleReadResponse alertingRules = client.readRules("alert");
NOTE: The Parameter Approach
can break if the API changes. The Consumer Specification Approach
is more resilient to API changes.
Released under the MIT License.