Package com.google.cloud.logging
Class Metric
- java.lang.Object
-
- com.google.cloud.logging.MetricInfo
-
- com.google.cloud.logging.Metric
-
- All Implemented Interfaces:
Serializable
public class Metric extends MetricInfo
Cloud Logging metrics describe logs-based metric. The value of the metric is the number of log entries that match a logs filter (seeMetricInfo.getFilter()).Metricadds a layer of service-related functionality overMetricInfo. Objects of this class are immutable. To get aMetricobject with the most recent information usereload()orreloadAsync().- See Also:
- Logs-based Metrics , Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMetric.BuilderA builder forMetricobjects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandelete()Deletes this metric.com.google.api.core.ApiFuture<Boolean>deleteAsync()Sends a request for deleting this metric.booleanequals(Object obj)LogginggetLogging()Returns the metrics'sLoggingobject used to issue requests.inthashCode()Metricreload()Fetches current metric's latest information.com.google.api.core.ApiFuture<Metric>reloadAsync()Sends a request to fetch current metric's latest information.Metric.BuildertoBuilder()Returns a builder for thisMetricInfoobject.Metricupdate()Updates current metric.com.google.api.core.ApiFuture<Metric>updateAsync()Sends a request to update current metric.-
Methods inherited from class com.google.cloud.logging.MetricInfo
getDescription, getFilter, getName, newBuilder, of, toString
-
-
-
-
Method Detail
-
toBuilder
public Metric.Builder toBuilder()
Description copied from class:MetricInfoReturns a builder for thisMetricInfoobject.- Overrides:
toBuilderin classMetricInfo
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classMetricInfo
-
equals
public final boolean equals(Object obj)
- Overrides:
equalsin classMetricInfo
-
getLogging
public Logging 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
public com.google.api.core.ApiFuture<Boolean> 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
public Metric 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
public com.google.api.core.ApiFuture<Metric> 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
public Metric 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
public com.google.api.core.ApiFuture<Metric> 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
-
-