Class: Fog::Google::Monitoring::Real

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/google/requests/monitoring/list_timeseries.rb,
lib/fog/google/monitoring/real.rb,
lib/fog/google/requests/monitoring/create_timeseries.rb,
lib/fog/google/requests/monitoring/get_metric_descriptor.rb,
lib/fog/google/requests/monitoring/list_metric_descriptors.rb,
lib/fog/google/requests/monitoring/create_metric_descriptor.rb,
lib/fog/google/requests/monitoring/delete_metric_descriptor.rb,
lib/fog/google/requests/monitoring/get_monitored_resource_descriptor.rb,
lib/fog/google/requests/monitoring/list_monitored_resource_descriptors.rb

Overview

Describes the schema of a MonitoredResource (a resource object that can be used for monitoring, logging, billing, or other purposes) using a type name and a set of labels.

Instance Attribute Summary collapse

Attributes included from Shared

#api_url, #api_version, #project

Instance Method Summary collapse

Methods included from Shared

#apply_client_options, #build_excon_response, #initialize_auth, #initialize_google_client, #request, #shared_initialize

Constructor Details

#initialize(options) ⇒ Real

Returns a new instance of Real.



9
10
11
12
13
14
15
16
# File 'lib/fog/google/monitoring/real.rb', line 9

def initialize(options)
  shared_initialize(options[:google_project], GOOGLE_MONITORING_API_VERSION, GOOGLE_MONITORING_BASE_URL)
  options[:google_api_scope_url] = GOOGLE_MONITORING_API_SCOPE_URLS.join(" ")

  initialize_google_client(options)
  @monitoring = ::Google::Apis::MonitoringV3::MonitoringService.new
  apply_client_options(@monitoring, options)
end

Instance Attribute Details

#monitoringObject (readonly)

Returns the value of attribute monitoring.



7
8
9
# File 'lib/fog/google/monitoring/real.rb', line 7

def monitoring
  @monitoring
end

Instance Method Details

#create_metric_descriptor(metric_type: nil, unit: nil, value_type: nil, description: nil, display_name: nil, labels: [], metric_kind: nil) ⇒ ::Google::Apis::MonitoringV3::MetricDescriptor

Create a metric descriptor. User-created metric descriptors define custom metrics.

Parameters:

  • metric_type (String) (defaults to: nil)

    Required - the metric type. User-created metric descriptors should start with custom.googleapis.com.

  • unit (String) (defaults to: nil)

    The unit in which the metric value is reported. It is only applicable if the valueType is INT64, DOUBLE, or DISTRIBUTION.

  • value_type (String) (defaults to: nil)

    Whether the measurement is an integer, a floating-point number, etc. Some combinations of metricKind and valueType might not be supported.

  • description (String) (defaults to: nil)

    A detailed description of the metric, which can be used in documentation.

  • display_name (String) (defaults to: nil)

    A concise name for the metric, which can be displayed in user interfaces. Use sentence casing without an ending period, for example “Request count”.

  • labels (Array<Hash>) (defaults to: [])

    A list of label hash objects that can be used to describe a specific instance of this metric type.

  • metric_kind (String) (defaults to: nil)

    The pagination token, which is used to page through large result sets.

Options Hash (labels:):

  • key (String)

    The label key.

  • value_type (String)

    The type of data that can be assigned to the label.

  • description (String)

    A human-readable description for the label.

Returns:

  • (::Google::Apis::MonitoringV3::MetricDescriptor)

    created metric descriptor

See Also:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/google/requests/monitoring/create_metric_descriptor.rb', line 25

def create_metric_descriptor(metric_type: nil, unit: nil, value_type: nil,
                             description: nil, display_name: nil, labels: [], metric_kind: nil)
  metric_descriptor = ::Google::Apis::MonitoringV3::MetricDescriptor.new(
    name: "projects/#{@project}/metricDescriptors/#{metric_type}",
    type: metric_type,
    unit: unit,
    value_type: value_type,
    description: description,
    display_name: display_name,
    labels: labels.map { |l| ::Google::Apis::MonitoringV3::LabelDescriptor.new(**l) },
    metric_kind: metric_kind
  )

  @monitoring.create_project_metric_descriptor("projects/#{@project}", metric_descriptor)
end

#create_timeseries(timeseries: []) ⇒ Object

Create a timeseries. User-created time series should only be used with custom metrics.

Parameters:

See Also:



12
13
14
15
16
17
# File 'lib/fog/google/requests/monitoring/create_timeseries.rb', line 12

def create_timeseries(timeseries: [])
  request = ::Google::Apis::MonitoringV3::CreateTimeSeriesRequest.new(
    time_series: timeseries
  )
  @monitoring.create_project_time_series("projects/#{@project}", request)
end

#delete_metric_descriptor(metric_type) ⇒ Object



5
6
7
# File 'lib/fog/google/requests/monitoring/delete_metric_descriptor.rb', line 5

def delete_metric_descriptor(metric_type)
  @monitoring.delete_project_metric_descriptor("projects/#{@project}/metricDescriptors/#{metric_type}")
end

#get_metric_descriptor(metric_type) ⇒ Object



5
6
7
# File 'lib/fog/google/requests/monitoring/get_metric_descriptor.rb', line 5

def get_metric_descriptor(metric_type)
  @monitoring.get_project_metric_descriptor("projects/#{@project}/metricDescriptors/#{metric_type}")
end

#get_monitored_resource_descriptor(resource_type) ⇒ Object



5
6
7
8
9
# File 'lib/fog/google/requests/monitoring/get_monitored_resource_descriptor.rb', line 5

def get_monitored_resource_descriptor(resource_type)
  @monitoring.get_project_monitored_resource_descriptor(
    "projects/#{@project}/monitoredResourceDescriptors/#{resource_type}"
  )
end

#list_metric_descriptors(filter: nil, page_size: nil, page_token: nil) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/fog/google/requests/monitoring/list_metric_descriptors.rb', line 9

def list_metric_descriptors(filter: nil, page_size: nil, page_token: nil)
  @monitoring.list_project_metric_descriptors(
    "projects/#{@project}",
    :filter => filter,
    :page_size => page_size,
    :page_token => page_token
  )
end

#list_monitored_resource_descriptors(filter: nil, page_size: nil, page_token: nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/fog/google/requests/monitoring/list_monitored_resource_descriptors.rb', line 10

def list_monitored_resource_descriptors(filter: nil, page_size: nil, page_token: nil)
  @monitoring.list_project_monitored_resource_descriptors(
    "projects/#{@project}",
    :filter => filter,
    :page_size => page_size,
    :page_token => page_token
  )
end

#list_timeseries(filter: nil, interval: nil, aggregation: nil, order_by: nil, page_size: nil, page_token: nil, view: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/google/requests/monitoring/list_timeseries.rb', line 10

def list_timeseries(filter: nil, interval: nil, aggregation: nil, order_by: nil, page_size: nil, page_token: nil, view: nil)
  if filter.nil?
    raise ArgumentError.new("filter is required")
  end

  if interval.nil?
    raise ArgumentError.new("interval is required")
  end

  options = {
    :filter => filter,
    :interval_end_time => interval[:end_time],
    :interval_start_time => interval[:start_time],
    :order_by => order_by,
    :page_size => page_size,
    :page_token => page_token,
    :view => view
  }
  if options.key?(:interval)
    interval = options[:interval]
    parameters["interval.endTime"] = interval[:end_time] if interval.key?(:end_time)
    parameters["interval.startTime"] = interval[:start_time] if interval.key?(:start_time)
  end

  unless aggregation.nil?
    %i(alignment_period cross_series_reducer group_by_fields per_series_aligner).each do |k|
      if aggregation.key?(k)
        options["aggregation_#{k}".to_sym] = aggregation[k]
      end
    end
  end

  @monitoring.list_project_time_series("projects/#{@project}", **options)
end