@Generated(value="by gapic-generator") public class MetricServiceClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(name);
}
Note: close() needs to be called on the metricServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of MetricServiceSettings to create(). For example:
To customize credentials:
MetricServiceSettings metricServiceSettings =
MetricServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
MetricServiceClient metricServiceClient =
MetricServiceClient.create(metricServiceSettings);
To customize the endpoint:
MetricServiceSettings metricServiceSettings =
MetricServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
MetricServiceClient metricServiceClient =
MetricServiceClient.create(metricServiceSettings);
Modifier and Type | Class and Description |
---|---|
static class |
MetricServiceClient.ListMetricDescriptorsFixedSizeCollection |
static class |
MetricServiceClient.ListMetricDescriptorsPage |
static class |
MetricServiceClient.ListMetricDescriptorsPagedResponse |
static class |
MetricServiceClient.ListMonitoredResourceDescriptorsFixedSizeCollection |
static class |
MetricServiceClient.ListMonitoredResourceDescriptorsPage |
static class |
MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse |
static class |
MetricServiceClient.ListTimeSeriesFixedSizeCollection |
static class |
MetricServiceClient.ListTimeSeriesPage |
static class |
MetricServiceClient.ListTimeSeriesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
MetricServiceClient(MetricServiceSettings settings)
Constructs an instance of MetricServiceClient, using the given settings.
|
protected |
MetricServiceClient(MetricServiceStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static MetricServiceClient |
create()
Constructs an instance of MetricServiceClient with default settings.
|
static MetricServiceClient |
create(MetricServiceSettings settings)
Constructs an instance of MetricServiceClient, using the given settings.
|
static MetricServiceClient |
create(MetricServiceStub stub)
Constructs an instance of MetricServiceClient, using the given stub for making calls.
|
com.google.api.MetricDescriptor |
createMetricDescriptor(com.google.monitoring.v3.CreateMetricDescriptorRequest request)
Creates a new metric descriptor.
|
com.google.api.MetricDescriptor |
createMetricDescriptor(com.google.monitoring.v3.ProjectName name,
com.google.api.MetricDescriptor metricDescriptor)
Creates a new metric descriptor.
|
com.google.api.MetricDescriptor |
createMetricDescriptor(String name,
com.google.api.MetricDescriptor metricDescriptor)
Creates a new metric descriptor.
|
UnaryCallable<com.google.monitoring.v3.CreateMetricDescriptorRequest,com.google.api.MetricDescriptor> |
createMetricDescriptorCallable()
Creates a new metric descriptor.
|
void |
createTimeSeries(com.google.monitoring.v3.CreateTimeSeriesRequest request)
Creates or adds data to one or more time series.
|
void |
createTimeSeries(com.google.monitoring.v3.ProjectName name,
List<com.google.monitoring.v3.TimeSeries> timeSeries)
Creates or adds data to one or more time series.
|
void |
createTimeSeries(String name,
List<com.google.monitoring.v3.TimeSeries> timeSeries)
Creates or adds data to one or more time series.
|
UnaryCallable<com.google.monitoring.v3.CreateTimeSeriesRequest,Empty> |
createTimeSeriesCallable()
Creates or adds data to one or more time series.
|
void |
deleteMetricDescriptor(com.google.monitoring.v3.DeleteMetricDescriptorRequest request)
Deletes a metric descriptor.
|
void |
deleteMetricDescriptor(com.google.monitoring.v3.MetricDescriptorName name)
Deletes a metric descriptor.
|
void |
deleteMetricDescriptor(String name)
Deletes a metric descriptor.
|
UnaryCallable<com.google.monitoring.v3.DeleteMetricDescriptorRequest,Empty> |
deleteMetricDescriptorCallable()
Deletes a metric descriptor.
|
com.google.api.MetricDescriptor |
getMetricDescriptor(com.google.monitoring.v3.GetMetricDescriptorRequest request)
Gets a single metric descriptor.
|
com.google.api.MetricDescriptor |
getMetricDescriptor(com.google.monitoring.v3.MetricDescriptorName name)
Gets a single metric descriptor.
|
com.google.api.MetricDescriptor |
getMetricDescriptor(String name)
Gets a single metric descriptor.
|
UnaryCallable<com.google.monitoring.v3.GetMetricDescriptorRequest,com.google.api.MetricDescriptor> |
getMetricDescriptorCallable()
Gets a single metric descriptor.
|
com.google.api.MonitoredResourceDescriptor |
getMonitoredResourceDescriptor(com.google.monitoring.v3.GetMonitoredResourceDescriptorRequest request)
Gets a single monitored resource descriptor.
|
com.google.api.MonitoredResourceDescriptor |
getMonitoredResourceDescriptor(com.google.monitoring.v3.MonitoredResourceDescriptorName name)
Gets a single monitored resource descriptor.
|
com.google.api.MonitoredResourceDescriptor |
getMonitoredResourceDescriptor(String name)
Gets a single monitored resource descriptor.
|
UnaryCallable<com.google.monitoring.v3.GetMonitoredResourceDescriptorRequest,com.google.api.MonitoredResourceDescriptor> |
getMonitoredResourceDescriptorCallable()
Gets a single monitored resource descriptor.
|
MetricServiceSettings |
getSettings() |
MetricServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
MetricServiceClient.ListMetricDescriptorsPagedResponse |
listMetricDescriptors(com.google.monitoring.v3.ListMetricDescriptorsRequest request)
Lists metric descriptors that match a filter.
|
MetricServiceClient.ListMetricDescriptorsPagedResponse |
listMetricDescriptors(com.google.monitoring.v3.ProjectName name)
Lists metric descriptors that match a filter.
|
MetricServiceClient.ListMetricDescriptorsPagedResponse |
listMetricDescriptors(String name)
Lists metric descriptors that match a filter.
|
UnaryCallable<com.google.monitoring.v3.ListMetricDescriptorsRequest,com.google.monitoring.v3.ListMetricDescriptorsResponse> |
listMetricDescriptorsCallable()
Lists metric descriptors that match a filter.
|
UnaryCallable<com.google.monitoring.v3.ListMetricDescriptorsRequest,MetricServiceClient.ListMetricDescriptorsPagedResponse> |
listMetricDescriptorsPagedCallable()
Lists metric descriptors that match a filter.
|
MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse |
listMonitoredResourceDescriptors(com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest request)
Lists monitored resource descriptors that match a filter.
|
MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse |
listMonitoredResourceDescriptors(com.google.monitoring.v3.ProjectName name)
Lists monitored resource descriptors that match a filter.
|
MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse |
listMonitoredResourceDescriptors(String name)
Lists monitored resource descriptors that match a filter.
|
UnaryCallable<com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest,com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse> |
listMonitoredResourceDescriptorsCallable()
Lists monitored resource descriptors that match a filter.
|
UnaryCallable<com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest,MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse> |
listMonitoredResourceDescriptorsPagedCallable()
Lists monitored resource descriptors that match a filter.
|
MetricServiceClient.ListTimeSeriesPagedResponse |
listTimeSeries(com.google.monitoring.v3.ListTimeSeriesRequest request)
Lists time series that match a filter.
|
MetricServiceClient.ListTimeSeriesPagedResponse |
listTimeSeries(com.google.monitoring.v3.ProjectName name,
String filter,
com.google.monitoring.v3.TimeInterval interval,
com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView view)
Lists time series that match a filter.
|
MetricServiceClient.ListTimeSeriesPagedResponse |
listTimeSeries(String name,
String filter,
com.google.monitoring.v3.TimeInterval interval,
com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView view)
Lists time series that match a filter.
|
UnaryCallable<com.google.monitoring.v3.ListTimeSeriesRequest,com.google.monitoring.v3.ListTimeSeriesResponse> |
listTimeSeriesCallable()
Lists time series that match a filter.
|
UnaryCallable<com.google.monitoring.v3.ListTimeSeriesRequest,MetricServiceClient.ListTimeSeriesPagedResponse> |
listTimeSeriesPagedCallable()
Lists time series that match a filter.
|
void |
shutdown() |
void |
shutdownNow() |
protected MetricServiceClient(MetricServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected MetricServiceClient(MetricServiceStub stub)
public static final MetricServiceClient create() throws IOException
IOException
public static final MetricServiceClient create(MetricServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final MetricServiceClient create(MetricServiceStub stub)
public final MetricServiceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public MetricServiceStub getStub()
public final MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse listMonitoredResourceDescriptors(com.google.monitoring.v3.ProjectName name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
for (MonitoredResourceDescriptor element : metricServiceClient.listMonitoredResourceDescriptors(name).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.ApiException
- if the remote call failspublic final MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse listMonitoredResourceDescriptors(String name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
for (MonitoredResourceDescriptor element : metricServiceClient.listMonitoredResourceDescriptors(name.toString()).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.ApiException
- if the remote call failspublic final MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse listMonitoredResourceDescriptors(com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
.setName(name.toString())
.build();
for (MonitoredResourceDescriptor element : metricServiceClient.listMonitoredResourceDescriptors(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest,MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsPagedCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<ListMonitoredResourceDescriptorsPagedResponse> future = metricServiceClient.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
// Do something
for (MonitoredResourceDescriptor element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest,com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
.setName(name.toString())
.build();
while (true) {
ListMonitoredResourceDescriptorsResponse response = metricServiceClient.listMonitoredResourceDescriptorsCallable().call(request);
for (MonitoredResourceDescriptor element : response.getResourceDescriptorsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.api.MonitoredResourceDescriptor getMonitoredResourceDescriptor(com.google.monitoring.v3.MonitoredResourceDescriptorName name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(name);
}
name
- The monitored resource descriptor to get. The format is
`"projects/{project_id_or_number}/monitoredResourceDescriptors/{resource_type}"`. The
`{resource_type}` is a predefined type, such as `cloudsql_database`.ApiException
- if the remote call failspublic final com.google.api.MonitoredResourceDescriptor getMonitoredResourceDescriptor(String name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(name.toString());
}
name
- The monitored resource descriptor to get. The format is
`"projects/{project_id_or_number}/monitoredResourceDescriptors/{resource_type}"`. The
`{resource_type}` is a predefined type, such as `cloudsql_database`.ApiException
- if the remote call failspublic final com.google.api.MonitoredResourceDescriptor getMonitoredResourceDescriptor(com.google.monitoring.v3.GetMonitoredResourceDescriptorRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
GetMonitoredResourceDescriptorRequest request = GetMonitoredResourceDescriptorRequest.newBuilder()
.setName(name.toString())
.build();
MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.GetMonitoredResourceDescriptorRequest,com.google.api.MonitoredResourceDescriptor> getMonitoredResourceDescriptorCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
GetMonitoredResourceDescriptorRequest request = GetMonitoredResourceDescriptorRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<MonitoredResourceDescriptor> future = metricServiceClient.getMonitoredResourceDescriptorCallable().futureCall(request);
// Do something
MonitoredResourceDescriptor response = future.get();
}
public final MetricServiceClient.ListMetricDescriptorsPagedResponse listMetricDescriptors(com.google.monitoring.v3.ProjectName name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
for (MetricDescriptor element : metricServiceClient.listMetricDescriptors(name).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.ApiException
- if the remote call failspublic final MetricServiceClient.ListMetricDescriptorsPagedResponse listMetricDescriptors(String name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
for (MetricDescriptor element : metricServiceClient.listMetricDescriptors(name.toString()).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.ApiException
- if the remote call failspublic final MetricServiceClient.ListMetricDescriptorsPagedResponse listMetricDescriptors(com.google.monitoring.v3.ListMetricDescriptorsRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
.setName(name.toString())
.build();
for (MetricDescriptor element : metricServiceClient.listMetricDescriptors(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.ListMetricDescriptorsRequest,MetricServiceClient.ListMetricDescriptorsPagedResponse> listMetricDescriptorsPagedCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<ListMetricDescriptorsPagedResponse> future = metricServiceClient.listMetricDescriptorsPagedCallable().futureCall(request);
// Do something
for (MetricDescriptor element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.monitoring.v3.ListMetricDescriptorsRequest,com.google.monitoring.v3.ListMetricDescriptorsResponse> listMetricDescriptorsCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
.setName(name.toString())
.build();
while (true) {
ListMetricDescriptorsResponse response = metricServiceClient.listMetricDescriptorsCallable().call(request);
for (MetricDescriptor element : response.getMetricDescriptorsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.api.MetricDescriptor getMetricDescriptor(com.google.monitoring.v3.MetricDescriptorName name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
MetricDescriptor response = metricServiceClient.getMetricDescriptor(name);
}
name
- The metric descriptor on which to execute the request. The format is
`"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`. An example value of
`{metric_id}` is `"compute.googleapis.com/instance/disk/read_bytes_count"`.ApiException
- if the remote call failspublic final com.google.api.MetricDescriptor getMetricDescriptor(String name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
MetricDescriptor response = metricServiceClient.getMetricDescriptor(name.toString());
}
name
- The metric descriptor on which to execute the request. The format is
`"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`. An example value of
`{metric_id}` is `"compute.googleapis.com/instance/disk/read_bytes_count"`.ApiException
- if the remote call failspublic final com.google.api.MetricDescriptor getMetricDescriptor(com.google.monitoring.v3.GetMetricDescriptorRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
GetMetricDescriptorRequest request = GetMetricDescriptorRequest.newBuilder()
.setName(name.toString())
.build();
MetricDescriptor response = metricServiceClient.getMetricDescriptor(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.GetMetricDescriptorRequest,com.google.api.MetricDescriptor> getMetricDescriptorCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
GetMetricDescriptorRequest request = GetMetricDescriptorRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<MetricDescriptor> future = metricServiceClient.getMetricDescriptorCallable().futureCall(request);
// Do something
MetricDescriptor response = future.get();
}
public final com.google.api.MetricDescriptor createMetricDescriptor(com.google.monitoring.v3.ProjectName name, com.google.api.MetricDescriptor metricDescriptor)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
MetricDescriptor response = metricServiceClient.createMetricDescriptor(name, metricDescriptor);
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.metricDescriptor
- The new [custom metric](/monitoring/custom-metrics) descriptor.ApiException
- if the remote call failspublic final com.google.api.MetricDescriptor createMetricDescriptor(String name, com.google.api.MetricDescriptor metricDescriptor)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
MetricDescriptor response = metricServiceClient.createMetricDescriptor(name.toString(), metricDescriptor);
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.metricDescriptor
- The new [custom metric](/monitoring/custom-metrics) descriptor.ApiException
- if the remote call failspublic final com.google.api.MetricDescriptor createMetricDescriptor(com.google.monitoring.v3.CreateMetricDescriptorRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder()
.setName(name.toString())
.setMetricDescriptor(metricDescriptor)
.build();
MetricDescriptor response = metricServiceClient.createMetricDescriptor(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.CreateMetricDescriptorRequest,com.google.api.MetricDescriptor> createMetricDescriptorCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder()
.setName(name.toString())
.setMetricDescriptor(metricDescriptor)
.build();
ApiFuture<MetricDescriptor> future = metricServiceClient.createMetricDescriptorCallable().futureCall(request);
// Do something
MetricDescriptor response = future.get();
}
public final void deleteMetricDescriptor(com.google.monitoring.v3.MetricDescriptorName name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
metricServiceClient.deleteMetricDescriptor(name);
}
name
- The metric descriptor on which to execute the request. The format is
`"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`. An example of
`{metric_id}` is: `"custom.googleapis.com/my_test_metric"`.ApiException
- if the remote call failspublic final void deleteMetricDescriptor(String name)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
metricServiceClient.deleteMetricDescriptor(name.toString());
}
name
- The metric descriptor on which to execute the request. The format is
`"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`. An example of
`{metric_id}` is: `"custom.googleapis.com/my_test_metric"`.ApiException
- if the remote call failspublic final void deleteMetricDescriptor(com.google.monitoring.v3.DeleteMetricDescriptorRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder()
.setName(name.toString())
.build();
metricServiceClient.deleteMetricDescriptor(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.DeleteMetricDescriptorRequest,Empty> deleteMetricDescriptorCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
MetricDescriptorName name = MetricDescriptorName.of("[PROJECT]", "[METRIC_DESCRIPTOR]");
DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Void> future = metricServiceClient.deleteMetricDescriptorCallable().futureCall(request);
// Do something
future.get();
}
public final MetricServiceClient.ListTimeSeriesPagedResponse listTimeSeries(com.google.monitoring.v3.ProjectName name, String filter, com.google.monitoring.v3.TimeInterval interval, com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView view)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
String filter = "";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
for (TimeSeries element : metricServiceClient.listTimeSeries(name, filter, interval, view).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project on which to execute the request. The format is
"projects/{project_id_or_number}".filter
- A [monitoring filter](/monitoring/api/v3/filters) that specifies which time
series should be returned. The filter must specify a single metric type, and can
additionally specify metric labels and other information. For example:
metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND metric.label.instance_name = "my-instance-name"
interval
- The time interval for which results should be returned. Only time series that
contain data points in the specified interval are included in the response.view
- Specifies which information is returned about the time series.ApiException
- if the remote call failspublic final MetricServiceClient.ListTimeSeriesPagedResponse listTimeSeries(String name, String filter, com.google.monitoring.v3.TimeInterval interval, com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView view)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
String filter = "";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
for (TimeSeries element : metricServiceClient.listTimeSeries(name.toString(), filter, interval, view).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project on which to execute the request. The format is
"projects/{project_id_or_number}".filter
- A [monitoring filter](/monitoring/api/v3/filters) that specifies which time
series should be returned. The filter must specify a single metric type, and can
additionally specify metric labels and other information. For example:
metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND metric.label.instance_name = "my-instance-name"
interval
- The time interval for which results should be returned. Only time series that
contain data points in the specified interval are included in the response.view
- Specifies which information is returned about the time series.ApiException
- if the remote call failspublic final MetricServiceClient.ListTimeSeriesPagedResponse listTimeSeries(com.google.monitoring.v3.ListTimeSeriesRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
String filter = "";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
.setName(name.toString())
.setFilter(filter)
.setInterval(interval)
.setView(view)
.build();
for (TimeSeries element : metricServiceClient.listTimeSeries(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.ListTimeSeriesRequest,MetricServiceClient.ListTimeSeriesPagedResponse> listTimeSeriesPagedCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
String filter = "";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
.setName(name.toString())
.setFilter(filter)
.setInterval(interval)
.setView(view)
.build();
ApiFuture<ListTimeSeriesPagedResponse> future = metricServiceClient.listTimeSeriesPagedCallable().futureCall(request);
// Do something
for (TimeSeries element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.monitoring.v3.ListTimeSeriesRequest,com.google.monitoring.v3.ListTimeSeriesResponse> listTimeSeriesCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
String filter = "";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
.setName(name.toString())
.setFilter(filter)
.setInterval(interval)
.setView(view)
.build();
while (true) {
ListTimeSeriesResponse response = metricServiceClient.listTimeSeriesCallable().call(request);
for (TimeSeries element : response.getTimeSeriesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void createTimeSeries(com.google.monitoring.v3.ProjectName name, List<com.google.monitoring.v3.TimeSeries> timeSeries)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
metricServiceClient.createTimeSeries(name, timeSeries);
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.timeSeries
- The new data to be added to a list of time series. Adds at most one data
point to each of several time series. The new data point must be more recent than any other
point in its time series. Each `TimeSeries` value must fully specify a unique time series
by supplying all label values for the metric and the monitored resource.ApiException
- if the remote call failspublic final void createTimeSeries(String name, List<com.google.monitoring.v3.TimeSeries> timeSeries)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
metricServiceClient.createTimeSeries(name.toString(), timeSeries);
}
name
- The project on which to execute the request. The format is
`"projects/{project_id_or_number}"`.timeSeries
- The new data to be added to a list of time series. Adds at most one data
point to each of several time series. The new data point must be more recent than any other
point in its time series. Each `TimeSeries` value must fully specify a unique time series
by supplying all label values for the metric and the monitored resource.ApiException
- if the remote call failspublic final void createTimeSeries(com.google.monitoring.v3.CreateTimeSeriesRequest request)
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder()
.setName(name.toString())
.addAllTimeSeries(timeSeries)
.build();
metricServiceClient.createTimeSeries(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.CreateTimeSeriesRequest,Empty> createTimeSeriesCallable()
Sample code:
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder()
.setName(name.toString())
.addAllTimeSeries(timeSeries)
.build();
ApiFuture<Void> future = metricServiceClient.createTimeSeriesCallable().futureCall(request);
// Do something
future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.