List custom metric descriptors
List custom metric definitions; Cloud Monitoring describes the measurements used to track application health.
Call the Google Cloud REST API with the JDK HTTP client. Requires JDK 17+. Results reflect resources already created in your local project.
Discovery check · reads existing local state.
Save as Hello.java
import java.net.URI;
import java.net.http.*;
import java.time.Duration;
import java.util.Objects;
public class Hello {
public static void main(String[] args) throws Exception {
var project = Objects.requireNonNull(System.getenv("GOOGLE_CLOUD_PROJECT"));
var endpoint = Objects.requireNonNull(System.getenv("SERVICE_USAGE_EMULATOR_HOST"));
var url = URI.create(endpoint.replaceAll("/+$", "") + "/v3/projects/" + project + "/metricDescriptors?filter=metric.type%3Dstarts_with%28%22custom.googleapis.com%22%29");
var request = HttpRequest.newBuilder(url).timeout(Duration.ofSeconds(30)).GET().build();
var client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 400) {
throw new IllegalStateException(response.statusCode() + ": " + response.body());
}
System.out.println(response.body());
}
} Run the example
java Hello.java Verify the result
The request succeeds. An empty list or no printed rows is valid before matching resources exist. Continue with the documented workflows for a resource test.