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 (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:
  • Method Details

    • toBuilder

      public Metric.Builder toBuilder()
      Description copied from class: MetricInfo
      Returns a builder for this MetricInfo object.
      Overrides:
      toBuilder in class MetricInfo
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class MetricInfo
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class MetricInfo
    • getLogging

      public Logging getLogging()
      Returns the metrics's Logging 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

      public com.google.api.core.ApiFuture<Boolean> deleteAsync()
      Sends a request for deleting this metric. This method returns a ApiFuture object to consume the result. Future.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
       }
       
      Throws:
      LoggingException - upon failure
    • 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:
      a Metric object with latest information or null if 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 a ApiFuture object to consume the result. Future.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
       }
       
      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 Metric object 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 a ApiFuture object to consume the result. Future.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();
       
      Throws:
      LoggingException - upon failure