class Google::Cloud::Logging::Metric
# Metric
A logs-based [Google Cloud
Monitoring](cloud.google.com/monitoring/docs) metric. A metric is a measured value that can be used to assess a system. The basis of a logs-based metric is the collection of log entries that match a logs filter.
@see cloud.google.com/logging/docs/view/logs_based_metrics
Logs-based Metrics
@see cloud.google.com/monitoring/docs Google
Cloud
Monitoring
@example
require "google/cloud/logging" logging = Google::Cloud::Logging.new metric = logging.create_metric "errors", "severity>=ERROR"
Attributes
@private The gRPC Google::Cloud::Logging::V2::LogMetric object.
@private The gRPC Service
object.
Public Class Methods
@private New Metric
from a gRPC object.
# File lib/google/cloud/logging/metric.rb, line 150 def self.from_grpc grpc, service new.tap do |m| m.grpc = grpc m.service = service end end
@private Create an empty Metric
object.
# File lib/google/cloud/logging/metric.rb, line 51 def initialize @service = nil @grpc = Google::Cloud::Logging::V2::LogMetric.new end
Public Instance Methods
Permanently deletes the logs-based metric.
@return [Boolean] Returns `true` if the metric was deleted.
@example
require "google/cloud/logging" logging = Google::Cloud::Logging.new metric = logging.metric "severe_errors" metric.delete
# File lib/google/cloud/logging/metric.rb, line 142 def delete ensure_service! service.delete_metric name true end
The description of this metric, which is used in documentation.
# File lib/google/cloud/logging/metric.rb, line 68 def description grpc.description end
Updates the description of this metric, which is used in documentation.
# File lib/google/cloud/logging/metric.rb, line 75 def description= description grpc.description = description end
An [advanced logs filter](cloud.google.com/logging/docs/view/advanced_filters).
# File lib/google/cloud/logging/metric.rb, line 82 def filter grpc.filter end
Updates the [advanced logs filter](cloud.google.com/logging/docs/view/advanced_filters).
# File lib/google/cloud/logging/metric.rb, line 89 def filter= filter grpc.filter = filter end
The client-assigned metric identifier. Metric
identifiers are limited to 1000 characters and can include only the following characters: `A-Z`, `a-z`, `0-9`, and the special characters `_-.,+!*',()%/`. The forward-slash character (`/`) denotes a hierarchy of name pieces, and it cannot be the first character of the name.
# File lib/google/cloud/logging/metric.rb, line 62 def name grpc.name end
Reloads the logs-based metric with current data from the Logging
service.
@example
require "google/cloud/logging" logging = Google::Cloud::Logging.new metric = logging.metric "severe_errors" metric.filter = "Unwanted value" metric.reload! metric.filter #=> "logName:syslog"
# File lib/google/cloud/logging/metric.rb, line 123 def reload! ensure_service! @grpc = service.get_metric name true end
Updates the logs-based metric.
@example
require "google/cloud/logging" logging = Google::Cloud::Logging.new metric = logging.metric "severe_errors" metric.filter = "logName:syslog AND severity>=ERROR" metric.save
# File lib/google/cloud/logging/metric.rb, line 104 def save ensure_service! @grpc = service.update_metric name, description, filter true end
Protected Instance Methods
@private Raise an error unless an active connection to the service is available.
# File lib/google/cloud/logging/metric.rb, line 162 def ensure_service! raise "Must have active connection to service" unless service end