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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
delete()
Deletes this metric.com.google.api.core.ApiFuture<Boolean>
Sends a request for deleting this metric.final boolean
Returns the metrics'sLogging
object used to issue requests.final int
hashCode()
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 thisMetricInfo
object.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:MetricInfo
Returns a builder for thisMetricInfo
object.- Overrides:
toBuilder
in classMetricInfo
-
hashCode
public final int hashCode()- Overrides:
hashCode
in classMetricInfo
-
equals
- Overrides:
equals
in classMetricInfo
-
getLogging
Returns the metrics'sLogging
object 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:
true
if the metric was deleted,false
if it was not found- Throws:
LoggingException
- upon failure
-
deleteAsync
Sends a request for deleting this metric. This method returns aApiFuture
object to consume the result.Future.get()
returnstrue
if the metric was deleted,false
if 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. Returnsnull
if 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
Metric
object with latest information ornull
if not found - Throws:
LoggingException
- upon failure
-
reloadAsync
Sends a request to fetch current metric's latest information. This method returns aApiFuture
object to consume the result.Future.get()
returns aMetric
object with latest information ornull
if 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
Metric
object 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 aApiFuture
object to consume the result.Future.get()
returns aMetric
object 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
-