Class Metric (3.14.9)

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 (see #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: Logs-based Metrics

Inheritance

Object > MetricInfo > Metric

Methods

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
Type Description
boolean

true if the metric was deleted, false if it was not found

deleteAsync()

public ApiFuture<Boolean> deleteAsync()

Sends a request for deleting this metric. This method returns a ApiFuture object to consume the result. ApiFuture#get() returns true 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
 }
 
Returns
Type Description
ApiFuture<Boolean>

equals(Object obj)

public final boolean equals(Object obj)
Parameter
Name Description
obj Object
Returns
Type Description
boolean
Overrides

getLogging()

public Logging getLogging()

Returns the metrics's Logging object used to issue requests.

Returns
Type Description
Logging

hashCode()

public final int hashCode()
Returns
Type Description
int
Overrides

reload()

public Metric reload()

Fetches current metric's latest information. Returns null 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
Type Description
Metric

a Metric object with latest information or null if not found

reloadAsync()

public ApiFuture<Metric> reloadAsync()

Sends a request to fetch current metric's latest information. This method returns a ApiFuture object to consume the result. ApiFuture#get() returns a Metric object with latest information or null 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
 }
 
Returns
Type Description
ApiFuture<Metric>

toBuilder()

public Metric.Builder toBuilder()

Returns a builder for this MetricInfo object.

Returns
Type Description
Metric.Builder
Overrides

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
Type Description
Metric

a Metric object with updated information

updateAsync()

public ApiFuture<Metric> updateAsync()

Sends a request to update current metric. If the metric does not exist, it is created. This method returns a ApiFuture object to consume the result. ApiFuture#get() returns a Metric 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();
 
Returns
Type Description
ApiFuture<Metric>