@Generated(value="by GAPIC") @ExperimentalApi public class MetricsClient extends Object implements AutoCloseable
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 (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric response = metricsClient.getLogMetric(metricName);
}
Note: close() needs to be called on the metricsClient 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 MetricsSettings to create(). For example:
InstantiatingChannelProvider channelProvider =
MetricsSettings.defaultChannelProviderBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
MetricsSettings metricsSettings =
MetricsSettings.defaultBuilder().setChannelProvider(channelProvider).build();
MetricsClient metricsClient =
MetricsClient.create(metricsSettings);
Modifier | Constructor and Description |
---|---|
protected |
MetricsClient(MetricsSettings settings)
Constructs an instance of MetricsClient, using the given settings.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
cancelled.
|
static MetricsClient |
create()
Constructs an instance of MetricsClient with default settings.
|
static MetricsClient |
create(MetricsSettings settings)
Constructs an instance of MetricsClient, using the given settings.
|
com.google.logging.v2.LogMetric |
createLogMetric(com.google.logging.v2.CreateLogMetricRequest request)
Creates a logs-based metric.
|
com.google.logging.v2.LogMetric |
createLogMetric(com.google.logging.v2.ParentNameOneof parent,
com.google.logging.v2.LogMetric metric)
Creates a logs-based metric.
|
com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.CreateLogMetricRequest,com.google.logging.v2.LogMetric> |
createLogMetricCallable()
Creates a logs-based metric.
|
void |
deleteLogMetric(com.google.logging.v2.MetricNameOneof metricName)
Deletes a logs-based metric.
|
com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.DeleteLogMetricRequest,com.google.protobuf.Empty> |
deleteLogMetricCallable()
Deletes a logs-based metric.
|
com.google.logging.v2.LogMetric |
getLogMetric(com.google.logging.v2.MetricNameOneof metricName)
Gets a logs-based metric.
|
com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.GetLogMetricRequest,com.google.logging.v2.LogMetric> |
getLogMetricCallable()
Gets a logs-based metric.
|
MetricsSettings |
getSettings() |
PagedResponseWrappers.ListLogMetricsPagedResponse |
listLogMetrics(com.google.logging.v2.ListLogMetricsRequest request)
Lists logs-based metrics.
|
PagedResponseWrappers.ListLogMetricsPagedResponse |
listLogMetrics(com.google.logging.v2.ParentNameOneof parent)
Lists logs-based metrics.
|
com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.ListLogMetricsRequest,com.google.logging.v2.ListLogMetricsResponse> |
listLogMetricsCallable()
Lists logs-based metrics.
|
com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.ListLogMetricsRequest,PagedResponseWrappers.ListLogMetricsPagedResponse> |
listLogMetricsPagedCallable()
Lists logs-based metrics.
|
com.google.logging.v2.LogMetric |
updateLogMetric(com.google.logging.v2.MetricNameOneof metricName,
com.google.logging.v2.LogMetric metric)
Creates or updates a logs-based metric.
|
com.google.logging.v2.LogMetric |
updateLogMetric(com.google.logging.v2.UpdateLogMetricRequest request)
Creates or updates a logs-based metric.
|
com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.UpdateLogMetricRequest,com.google.logging.v2.LogMetric> |
updateLogMetricCallable()
Creates or updates a logs-based metric.
|
protected MetricsClient(MetricsSettings settings) throws IOException
IOException
public static final MetricsClient create() throws IOException
IOException
public static final MetricsClient create(MetricsSettings settings) throws IOException
IOException
public final MetricsSettings getSettings()
public final PagedResponseWrappers.ListLogMetricsPagedResponse listLogMetrics(com.google.logging.v2.ParentNameOneof parent)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
for (LogMetric element : metricsClient.listLogMetrics(parent).iterateAllElements()) {
// doThingsWith(element);
}
}
parent
- Required. The name of the project containing the metrics:
"projects/[PROJECT_ID]"
com.google.api.gax.grpc.ApiException
- if the remote call failspublic final PagedResponseWrappers.ListLogMetricsPagedResponse listLogMetrics(com.google.logging.v2.ListLogMetricsRequest request)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
.setParentWithParentNameOneof(parent)
.build();
for (LogMetric element : metricsClient.listLogMetrics(request).iterateAllElements()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.ListLogMetricsRequest,PagedResponseWrappers.ListLogMetricsPagedResponse> listLogMetricsPagedCallable()
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
.setParentWithParentNameOneof(parent)
.build();
ApiFuture<ListLogMetricsPagedResponse> future = metricsClient.listLogMetricsPagedCallable().futureCall(request);
// Do something
for (LogMetric element : future.get().iterateAllElements()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.ListLogMetricsRequest,com.google.logging.v2.ListLogMetricsResponse> listLogMetricsCallable()
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
.setParentWithParentNameOneof(parent)
.build();
while (true) {
ListLogMetricsResponse response = metricsClient.listLogMetricsCallable().call(request);
for (LogMetric element : response.getMetricsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.logging.v2.LogMetric getLogMetric(com.google.logging.v2.MetricNameOneof metricName)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric response = metricsClient.getLogMetric(metricName);
}
metricName
- The resource name of the desired metric:
"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.GetLogMetricRequest,com.google.logging.v2.LogMetric> getLogMetricCallable()
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
GetLogMetricRequest request = GetLogMetricRequest.newBuilder()
.setMetricNameWithMetricNameOneof(metricName)
.build();
ApiFuture<LogMetric> future = metricsClient.getLogMetricCallable().futureCall(request);
// Do something
LogMetric response = future.get();
}
public final com.google.logging.v2.LogMetric createLogMetric(com.google.logging.v2.ParentNameOneof parent, com.google.logging.v2.LogMetric metric)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
LogMetric metric = LogMetric.newBuilder().build();
LogMetric response = metricsClient.createLogMetric(parent, metric);
}
parent
- The resource name of the project in which to create the metric:
"projects/[PROJECT_ID]"
The new metric must be provided in the request.
metric
- The new logs-based metric, which must not have an identifier that already exists.com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.logging.v2.LogMetric createLogMetric(com.google.logging.v2.CreateLogMetricRequest request)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
LogMetric metric = LogMetric.newBuilder().build();
CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder()
.setParentWithParentNameOneof(parent)
.setMetric(metric)
.build();
LogMetric response = metricsClient.createLogMetric(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.CreateLogMetricRequest,com.google.logging.v2.LogMetric> createLogMetricCallable()
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
LogMetric metric = LogMetric.newBuilder().build();
CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder()
.setParentWithParentNameOneof(parent)
.setMetric(metric)
.build();
ApiFuture<LogMetric> future = metricsClient.createLogMetricCallable().futureCall(request);
// Do something
LogMetric response = future.get();
}
public final com.google.logging.v2.LogMetric updateLogMetric(com.google.logging.v2.MetricNameOneof metricName, com.google.logging.v2.LogMetric metric)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric metric = LogMetric.newBuilder().build();
LogMetric response = metricsClient.updateLogMetric(metricName, metric);
}
metricName
- The resource name of the metric to update:
"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
The updated metric must be provided in the request and it's `name` field must be the same as `[METRIC_ID]` If the metric does not exist in `[PROJECT_ID]`, then a new metric is created.
metric
- The updated metric.com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.logging.v2.LogMetric updateLogMetric(com.google.logging.v2.UpdateLogMetricRequest request)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric metric = LogMetric.newBuilder().build();
UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder()
.setMetricNameWithMetricNameOneof(metricName)
.setMetric(metric)
.build();
LogMetric response = metricsClient.updateLogMetric(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.UpdateLogMetricRequest,com.google.logging.v2.LogMetric> updateLogMetricCallable()
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric metric = LogMetric.newBuilder().build();
UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder()
.setMetricNameWithMetricNameOneof(metricName)
.setMetric(metric)
.build();
ApiFuture<LogMetric> future = metricsClient.updateLogMetricCallable().futureCall(request);
// Do something
LogMetric response = future.get();
}
public final void deleteLogMetric(com.google.logging.v2.MetricNameOneof metricName)
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
metricsClient.deleteLogMetric(metricName);
}
metricName
- The resource name of the metric to delete:
"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.api.gax.grpc.UnaryCallable<com.google.logging.v2.DeleteLogMetricRequest,com.google.protobuf.Empty> deleteLogMetricCallable()
Sample code:
try (MetricsClient metricsClient = MetricsClient.create()) {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder()
.setMetricNameWithMetricNameOneof(metricName)
.build();
ApiFuture<Void> future = metricsClient.deleteLogMetricCallable().futureCall(request);
// Do something
future.get();
}
public final void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 2017 Google. All rights reserved.