Package com.google.cloud.logging
Class Metric
java.lang.Object
com.google.cloud.logging.MetricInfo
com.google.cloud.logging.Metric
- All Implemented Interfaces:
Serializable
Cloud Logging metrics describe logs-based metric. The value of the metric is the number of log
entries that match a logs filter (see
MetricInfo.getFilter()).
Metric adds a layer of service-related functionality over MetricInfo. Objects
of this class are immutable. To get a Metric object with the most recent information use
reload() or reloadAsync().
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbooleandelete()Deletes this metric.com.google.api.core.ApiFuture<Boolean>Sends a request for deleting this metric.final booleanReturns the metrics'sLoggingobject used to issue requests.final inthashCode()reload()Fetches current metric's latest information.com.google.api.core.ApiFuture<Metric>Sends a request to fetch current metric's latest information.Returns a builder for thisMetricInfoobject.update()Updates current metric.com.google.api.core.ApiFuture<Metric>Sends a request to update current metric.Methods inherited from class com.google.cloud.logging.MetricInfo
getDescription, getFilter, getName, newBuilder, of, toString
-
Method Details
-
toBuilder
Description copied from class:MetricInfoReturns a builder for thisMetricInfoobject.- Overrides:
toBuilderin classMetricInfo
-
hashCode
public final int hashCode()- Overrides:
hashCodein classMetricInfo
-
equals
- Overrides:
equalsin classMetricInfo
-
getLogging
Returns the metrics'sLoggingobject used to issue requests. -
delete
public boolean delete()Deletes this metric.Example of deleting the metric.
boolean deleted = metric.delete(); if (deleted) { // the metric was deleted } else { // the metric was not found }- Returns:
trueif the metric was deleted,falseif it was not found- Throws:
LoggingException- upon failure
-
deleteAsync
Sends a request for deleting this metric. This method returns aApiFutureobject to consume the result.Future.get()returnstrueif the metric was deleted,falseif it was not found.Example of asynchronously deleting the metric.
ApiFuture<Boolean> future = metric.deleteAsync(); // ... boolean deleted = future.get(); if (deleted) { // the metric was deleted } else { // the metric was not found }- Throws:
LoggingException- upon failure
-
reload
Fetches current metric's latest information. Returnsnullif the metric does not exist.Example of getting the metric's latest information.
Metric latestMetric = metric.reload(); if (latestMetric == null) { // the metric was not found }- Returns:
- a
Metricobject with latest information ornullif not found - Throws:
LoggingException- upon failure
-
reloadAsync
Sends a request to fetch current metric's latest information. This method returns aApiFutureobject to consume the result.Future.get()returns aMetricobject with latest information ornullif not found.Example of asynchronously getting the metric's latest information.
ApiFuture<Metric> future = metric.reloadAsync(); // ... Metric latestMetric = future.get(); if (latestMetric == null) { // the metric was not found }- Throws:
LoggingException- upon failure
-
update
Updates current metric. If the metric does not exist, it is created.Example of updating the metric's information.
Metric updatedMetric = metric.toBuilder() .setDescription("A more detailed description") .build() .update();- Returns:
- a
Metricobject with updated information - Throws:
LoggingException- upon failure
-
updateAsync
Sends a request to update current metric. If the metric does not exist, it is created. This method returns aApiFutureobject to consume the result.Future.get()returns aMetricobject with updated information.Example of asynchronously updating the metric's information.
ApiFuture<Metric> future = metric.toBuilder() .setDescription("A more detailed description") .build() .updateAsync(); // ... Metric updatedMetric = future.get();- Throws:
LoggingException- upon failure
-