@Generated(value="by GAPIC") public class MetricsServiceV2Api 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 (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
LogMetric response = metricsServiceV2Api.getLogMetric(formattedMetricName);
}
Note: close() needs to be called on the metricsServiceV2Api 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 MetricsServiceV2Settings to create(). For example:
MetricsServiceV2Settings metricsServiceV2Settings = MetricsServiceV2Settings.defaultBuilder()
.provideChannelWith(myCredentials)
.build();
MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create(metricsServiceV2Settings);
| Modifier | Constructor and Description |
|---|---|
protected |
MetricsServiceV2Api(MetricsServiceV2Settings settings)
Constructs an instance of MetricsServiceV2Api, 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 MetricsServiceV2Api |
create()
Constructs an instance of MetricsServiceV2Api with default settings.
|
static MetricsServiceV2Api |
create(MetricsServiceV2Settings settings)
Constructs an instance of MetricsServiceV2Api, 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(String parent,
com.google.logging.v2.LogMetric metric)
Creates a logs-based metric.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.CreateLogMetricRequest,com.google.logging.v2.LogMetric> |
createLogMetricCallable()
Creates a logs-based metric.
|
void |
deleteLogMetric(String metricName)
Deletes a logs-based metric.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.DeleteLogMetricRequest,com.google.protobuf.Empty> |
deleteLogMetricCallable()
Deletes a logs-based metric.
|
static String |
formatMetricName(String project,
String metric)
Formats a string containing the fully-qualified path to represent
a metric resource.
|
static String |
formatParentName(String project)
Formats a string containing the fully-qualified path to represent
a parent resource.
|
com.google.logging.v2.LogMetric |
getLogMetric(String metricName)
Gets a logs-based metric.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.GetLogMetricRequest,com.google.logging.v2.LogMetric> |
getLogMetricCallable()
Gets a logs-based metric.
|
MetricsServiceV2Settings |
getSettings() |
com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogMetric> |
listLogMetrics(com.google.logging.v2.ListLogMetricsRequest request)
Lists logs-based metrics.
|
com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogMetric> |
listLogMetrics(String parent)
Lists logs-based metrics.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListLogMetricsRequest,com.google.logging.v2.ListLogMetricsResponse> |
listLogMetricsCallable()
Lists logs-based metrics.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListLogMetricsRequest,com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogMetric>> |
listLogMetricsPagedCallable()
Lists logs-based metrics.
|
static String |
parseMetricFromMetricName(String metricName)
Parses the metric from the given fully-qualified path which
represents a metric resource.
|
static String |
parseProjectFromMetricName(String metricName)
Parses the project from the given fully-qualified path which
represents a metric resource.
|
static String |
parseProjectFromParentName(String parentName)
Parses the project from the given fully-qualified path which
represents a parent resource.
|
com.google.logging.v2.LogMetric |
updateLogMetric(String 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.ApiCallable<com.google.logging.v2.UpdateLogMetricRequest,com.google.logging.v2.LogMetric> |
updateLogMetricCallable()
Creates or updates a logs-based metric.
|
protected MetricsServiceV2Api(MetricsServiceV2Settings settings) throws IOException
IOExceptionpublic final MetricsServiceV2Settings getSettings()
public static final String formatParentName(String project)
public static final String formatMetricName(String project, String metric)
public static final String parseProjectFromParentName(String parentName)
public static final String parseProjectFromMetricName(String metricName)
public static final String parseMetricFromMetricName(String metricName)
public static final MetricsServiceV2Api create() throws IOException
IOExceptionpublic static final MetricsServiceV2Api create(MetricsServiceV2Settings settings) throws IOException
IOExceptionpublic final com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogMetric> listLogMetrics(String parent)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
for (LogMetric element : metricsServiceV2Api.listLogMetrics(formattedParent)) {
// doThingsWith(element);
}
}
parent - Required. The resource name containing the metrics.
Example: `"projects/my-project-id"`.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogMetric> listLogMetrics(com.google.logging.v2.ListLogMetricsRequest request)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
.setParent(formattedParent)
.build();
for (LogMetric element : metricsServiceV2Api.listLogMetrics(request)) {
// 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.ApiCallable<com.google.logging.v2.ListLogMetricsRequest,com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogMetric>> listLogMetricsPagedCallable()
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
.setParent(formattedParent)
.build();
ListenableFuture<PageAccessor<LogMetric>> future = metricsServiceV2Api.listLogMetricsPagedCallable().futureCall(request);
// Do something
for (LogMetric element : future.get()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListLogMetricsRequest,com.google.logging.v2.ListLogMetricsResponse> listLogMetricsCallable()
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
.setParent(formattedParent)
.build();
while (true) {
ListLogMetricsResponse response = metricsServiceV2Api.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(String metricName)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
LogMetric response = metricsServiceV2Api.getLogMetric(formattedMetricName);
}
metricName - The resource name of the desired metric.
Example: `"projects/my-project-id/metrics/my-metric-id"`.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.GetLogMetricRequest,com.google.logging.v2.LogMetric> getLogMetricCallable()
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
GetLogMetricRequest request = GetLogMetricRequest.newBuilder()
.setMetricName(formattedMetricName)
.build();
ListenableFuture<LogMetric> future = metricsServiceV2Api.getLogMetricCallable().futureCall(request);
// Do something
LogMetric response = future.get();
}
public final com.google.logging.v2.LogMetric createLogMetric(String parent, com.google.logging.v2.LogMetric metric)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
LogMetric metric = LogMetric.newBuilder().build();
LogMetric response = metricsServiceV2Api.createLogMetric(formattedParent, metric);
}
parent - The resource name of the project in which to create the metric.
Example: `"projects/my-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)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
LogMetric metric = LogMetric.newBuilder().build();
CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder()
.setParent(formattedParent)
.setMetric(metric)
.build();
LogMetric response = metricsServiceV2Api.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.ApiCallable<com.google.logging.v2.CreateLogMetricRequest,com.google.logging.v2.LogMetric> createLogMetricCallable()
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
LogMetric metric = LogMetric.newBuilder().build();
CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder()
.setParent(formattedParent)
.setMetric(metric)
.build();
ListenableFuture<LogMetric> future = metricsServiceV2Api.createLogMetricCallable().futureCall(request);
// Do something
LogMetric response = future.get();
}
public final com.google.logging.v2.LogMetric updateLogMetric(String metricName, com.google.logging.v2.LogMetric metric)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
LogMetric metric = LogMetric.newBuilder().build();
LogMetric response = metricsServiceV2Api.updateLogMetric(formattedMetricName, metric);
}
metricName - The resource name of the metric to update.
Example: `"projects/my-project-id/metrics/my-metric-id"`.
The updated metric must be provided in the request and have the
same identifier that is specified in `metricName`.
If the metric does not exist, it is created.metric - The updated metric, whose name must be the same as the
metric identifier in `metricName`. If `metricName` does not
exist, then a new metric is created.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.logging.v2.LogMetric updateLogMetric(com.google.logging.v2.UpdateLogMetricRequest request)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
LogMetric metric = LogMetric.newBuilder().build();
UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder()
.setMetricName(formattedMetricName)
.setMetric(metric)
.build();
LogMetric response = metricsServiceV2Api.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.ApiCallable<com.google.logging.v2.UpdateLogMetricRequest,com.google.logging.v2.LogMetric> updateLogMetricCallable()
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
LogMetric metric = LogMetric.newBuilder().build();
UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder()
.setMetricName(formattedMetricName)
.setMetric(metric)
.build();
ListenableFuture<LogMetric> future = metricsServiceV2Api.updateLogMetricCallable().futureCall(request);
// Do something
LogMetric response = future.get();
}
public final void deleteLogMetric(String metricName)
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
metricsServiceV2Api.deleteLogMetric(formattedMetricName);
}
metricName - The resource name of the metric to delete.
Example: `"projects/my-project-id/metrics/my-metric-id"`.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.DeleteLogMetricRequest,com.google.protobuf.Empty> deleteLogMetricCallable()
try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]");
DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder()
.setMetricName(formattedMetricName)
.build();
ListenableFuture<Void> future = metricsServiceV2Api.deleteLogMetricCallable().futureCall(request);
// Do something
future.get();
}
public final void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2016 Google. All rights reserved.