|
24 | 24 | import com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse;
|
25 | 25 | import com.google.cloud.monitoring.v3.MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse;
|
26 | 26 | import com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse;
|
| 27 | +import com.google.gson.Gson; |
27 | 28 | import com.google.monitoring.v3.Aggregation;
|
28 | 29 | import com.google.monitoring.v3.CreateMetricDescriptorRequest;
|
29 | 30 | import com.google.monitoring.v3.CreateTimeSeriesRequest;
|
|
39 | 40 | import com.google.monitoring.v3.TypedValue;
|
40 | 41 | import com.google.protobuf.Duration;
|
41 | 42 | import com.google.protobuf.util.Timestamps;
|
| 43 | + |
42 | 44 | import java.io.IOException;
|
43 | 45 | import java.util.ArrayList;
|
44 | 46 | import java.util.HashMap;
|
|
49 | 51 |
|
50 | 52 |
|
51 | 53 | public class Snippets {
|
52 |
| - |
53 | 54 | private static final String CUSTOM_METRIC_DOMAIN = "custom.googleapis.com";
|
| 55 | + private static final Gson gson = new Gson(); |
54 | 56 |
|
55 | 57 | /**
|
56 | 58 | * Exercises the methods defined in this class.
|
@@ -392,6 +394,17 @@ void listMonitoredResources() throws IOException {
|
392 | 394 | // [END monitoring_list_resources]
|
393 | 395 | }
|
394 | 396 |
|
| 397 | + // [START monitoring_get_resource] |
| 398 | + void getMonitoredResource(String resourceId) throws IOException { |
| 399 | + String projectId = System.getProperty("projectId"); |
| 400 | + MetricServiceClient client = MetricServiceClient.create(); |
| 401 | + MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of(projectId, |
| 402 | + resourceId); |
| 403 | + MonitoredResourceDescriptor response = client.getMonitoredResourceDescriptor(name); |
| 404 | + System.out.println("Retrieved Monitored Resource: " + gson.toJson(response)); |
| 405 | + } |
| 406 | + // [END monitoring_get_resource] |
| 407 | + |
395 | 408 | /**
|
396 | 409 | * Gets full information for a monitored resource.
|
397 | 410 | *
|
|
0 commit comments