Class: Gcloud::Logging::Metric

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

Overview

Metric

A logs-based metric. The value of the metric is the number of log entries that match a logs filter.

Examples:

require "gcloud"

gcloud = Gcloud.new
logging = gcloud.logging
metric = logging.metric "severe_errors"

Defined Under Namespace

Classes: List

Instance Method Summary collapse

Instance Method Details

#deleteBoolean

Permanently deletes the logs-based metric.

Examples:

require "gcloud"

gcloud = Gcloud.new
logging = gcloud.logging
metric = logging.metric "severe_errors"
metric.delete

Returns:

  • (Boolean)

    Returns true if the metric was deleted.


134
135
136
137
138
139
140
141
142
# File 'lib/gcloud/logging/metric.rb', line 134

def delete
  ensure_connection!
  resp = connection.delete_metric name
  if resp.success?
    true
  else
    fail ApiError.from_response(resp)
  end
end

#descriptionObject

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


61
62
63
# File 'lib/gcloud/logging/metric.rb', line 61

def description
  @gapi["description"]
end

#description=(description) ⇒ Object

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


67
68
69
# File 'lib/gcloud/logging/metric.rb', line 67

def description= description
  @gapi["description"] = description
end

#filterObject


74
75
76
# File 'lib/gcloud/logging/metric.rb', line 74

def filter
  @gapi["filter"]
end

#filter=(filter) ⇒ Object

Updates the advanced logs filter.


81
82
83
# File 'lib/gcloud/logging/metric.rb', line 81

def filter= filter
  @gapi["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.


55
56
57
# File 'lib/gcloud/logging/metric.rb', line 55

def name
  @gapi["name"]
end

#reload!Object Also known as: refresh!

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


110
111
112
113
114
115
116
117
118
# File 'lib/gcloud/logging/metric.rb', line 110

def reload!
  ensure_connection!
  resp = connection.get_metric name
  if resp.success?
    @gapi = resp.data
  else
    fail ApiError.from_response(resp)
  end
end

#saveObject

Updates the logs-based metric.

Examples:

require "gcloud"

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

97
98
99
100
101
102
103
104
105
# File 'lib/gcloud/logging/metric.rb', line 97

def save
  ensure_connection!
  resp = connection.update_metric name, description, filter
  if resp.success?
    @gapi = resp.data
  else
    fail ApiError.from_response(resp)
  end
end