Class: Google::Cloud::Logging::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/logging/metric.rb,
lib/google/cloud/logging/metric/list.rb

Overview

# 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.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
logging = gcloud.logging
metric = logging.create_metric "errors", "severity>=ERROR"

See Also:

Defined Under Namespace

Classes: List

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetric



52
53
54
55
# File 'lib/google/cloud/logging/metric.rb', line 52

def initialize
  @service = nil
  @grpc = Google::Logging::V2::LogMetric.new
end

Instance Attribute Details

#grpcObject



48
49
50
# File 'lib/google/cloud/logging/metric.rb', line 48

def grpc
  @grpc
end

#serviceObject



44
45
46
# File 'lib/google/cloud/logging/metric.rb', line 44

def service
  @service
end

Class Method Details

.from_grpc(grpc, service) ⇒ Object



154
155
156
157
158
159
# File 'lib/google/cloud/logging/metric.rb', line 154

def self.from_grpc grpc, service
  new.tap do |m|
    m.grpc = grpc
    m.service = service
  end
end

Instance Method Details

#deleteBoolean

Permanently deletes the logs-based metric.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
logging = gcloud.logging
metric = logging.metric "severe_errors"
metric.delete


146
147
148
149
150
# File 'lib/google/cloud/logging/metric.rb', line 146

def delete
  ensure_service!
  service.delete_metric name
  true
end

#descriptionObject

The description of this metric, which is used in documentation.



69
70
71
# File 'lib/google/cloud/logging/metric.rb', line 69

def description
  grpc.description
end

#description=(description) ⇒ Object

Updates the description of this metric, which is used in documentation.



76
77
78
# File 'lib/google/cloud/logging/metric.rb', line 76

def description= description
  grpc.description = description
end

#filterObject



83
84
85
# File 'lib/google/cloud/logging/metric.rb', line 83

def filter
  grpc.filter
end

#filter=(filter) ⇒ Object

Updates the [advanced logs filter](cloud.google.com/logging/docs/view/advanced_filters).



90
91
92
# File 'lib/google/cloud/logging/metric.rb', line 90

def filter= filter
  grpc.filter = filter
end

#nameObject

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.



63
64
65
# File 'lib/google/cloud/logging/metric.rb', line 63

def name
  grpc.name
end

#reload!Object Also known as: refresh!

Reloads the logs-based metric with current data from the Logging service.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
logging = gcloud.logging
metric = logging.metric "severe_errors"
metric.filter = "Unwanted value"
metric.reload!
metric.filter #=> "logName:syslog"


126
127
128
129
130
# File 'lib/google/cloud/logging/metric.rb', line 126

def reload!
  ensure_service!
  @grpc = service.get_metric name
  true
end

#saveObject

Updates the logs-based metric.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
logging = gcloud.logging
metric = logging.metric "severe_errors"
metric.filter = "logName:syslog AND severity>=ERROR"
metric.save


106
107
108
109
110
# File 'lib/google/cloud/logging/metric.rb', line 106

def save
  ensure_service!
  @grpc = service.update_metric name, description, filter
  true
end