Cloud Monitoring V3 API - Class Google::Cloud::Monitoring::V3::MetricService::Client (v1.0.0)

Reference documentation and code samples for the Cloud Monitoring V3 API class Google::Cloud::Monitoring::V3::MetricService::Client.

Client for the MetricService service.

Manages metric descriptors, monitored resource descriptors, and time series data.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the MetricService Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all MetricService clients
::Google::Cloud::Monitoring::V3::MetricService::Client.configure do |config|
  config.timeout = 10.0
end

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the MetricService Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#create_metric_descriptor

def create_metric_descriptor(request, options = nil) -> ::Google::Api::MetricDescriptor
def create_metric_descriptor(name: nil, metric_descriptor: nil) -> ::Google::Api::MetricDescriptor

Creates a new metric descriptor. The creation is executed asynchronously. User-created metric descriptors define custom metrics. The metric descriptor is updated if it already exists, except that metric labels are never removed.

Overloads
def create_metric_descriptor(request, options = nil) -> ::Google::Api::MetricDescriptor
Pass arguments to create_metric_descriptor via a request object, either of type CreateMetricDescriptorRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::CreateMetricDescriptorRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def create_metric_descriptor(name: nil, metric_descriptor: nil) -> ::Google::Api::MetricDescriptor
Pass arguments to create_metric_descriptor via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::CreateMetricDescriptorRequest.new

# Call the create_metric_descriptor method.
result = client.create_metric_descriptor request

# The returned object is of type Google::Api::MetricDescriptor.
p result

#create_service_time_series

def create_service_time_series(request, options = nil) -> ::Google::Protobuf::Empty
def create_service_time_series(name: nil, time_series: nil) -> ::Google::Protobuf::Empty

Creates or adds data to one or more service time series. A service time series is a time series for a metric from a Google Cloud service. The response is empty if all time series in the request were written. If any time series could not be written, a corresponding failure message is included in the error response. This endpoint rejects writes to user-defined metrics. This method is only for use by Google Cloud services. Use projects.timeSeries.create instead.

Overloads
def create_service_time_series(request, options = nil) -> ::Google::Protobuf::Empty
Pass arguments to create_service_time_series via a request object, either of type CreateTimeSeriesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::CreateTimeSeriesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def create_service_time_series(name: nil, time_series: nil) -> ::Google::Protobuf::Empty
Pass arguments to create_service_time_series via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) —

    Required. The project on which to execute the request. The format is:

    projects/[PROJECT_ID_OR_NUMBER]
    
  • time_series (::Array<::Google::Cloud::Monitoring::V3::TimeSeries, ::Hash>) — Required. The new data to be added to a list of time series. Adds at most one data point to each of several time series. The new data point must be more recent than any other point in its time series. Each TimeSeries value must fully specify a unique time series by supplying all label values for the metric and the monitored resource.

    The maximum number of TimeSeries objects per Create request is 200.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::CreateTimeSeriesRequest.new

# Call the create_service_time_series method.
result = client.create_service_time_series request

# The returned object is of type Google::Protobuf::Empty.
p result

#create_time_series

def create_time_series(request, options = nil) -> ::Google::Protobuf::Empty
def create_time_series(name: nil, time_series: nil) -> ::Google::Protobuf::Empty

Creates or adds data to one or more time series. The response is empty if all time series in the request were written. If any time series could not be written, a corresponding failure message is included in the error response. This method does not support resource locations constraint of an organization policy.

Overloads
def create_time_series(request, options = nil) -> ::Google::Protobuf::Empty
Pass arguments to create_time_series via a request object, either of type CreateTimeSeriesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::CreateTimeSeriesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def create_time_series(name: nil, time_series: nil) -> ::Google::Protobuf::Empty
Pass arguments to create_time_series via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) —

    Required. The project on which to execute the request. The format is:

    projects/[PROJECT_ID_OR_NUMBER]
    
  • time_series (::Array<::Google::Cloud::Monitoring::V3::TimeSeries, ::Hash>) — Required. The new data to be added to a list of time series. Adds at most one data point to each of several time series. The new data point must be more recent than any other point in its time series. Each TimeSeries value must fully specify a unique time series by supplying all label values for the metric and the monitored resource.

    The maximum number of TimeSeries objects per Create request is 200.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::CreateTimeSeriesRequest.new

# Call the create_time_series method.
result = client.create_time_series request

# The returned object is of type Google::Protobuf::Empty.
p result

#delete_metric_descriptor

def delete_metric_descriptor(request, options = nil) -> ::Google::Protobuf::Empty
def delete_metric_descriptor(name: nil) -> ::Google::Protobuf::Empty

Deletes a metric descriptor. Only user-created custom metrics can be deleted.

Overloads
def delete_metric_descriptor(request, options = nil) -> ::Google::Protobuf::Empty
Pass arguments to delete_metric_descriptor via a request object, either of type DeleteMetricDescriptorRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::DeleteMetricDescriptorRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def delete_metric_descriptor(name: nil) -> ::Google::Protobuf::Empty
Pass arguments to delete_metric_descriptor via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The metric descriptor on which to execute the request. The format is:

    projects/[PROJECT_ID_OR_NUMBER]/metricDescriptors/[METRIC_ID]
    

    An example of [METRIC_ID] is: "custom.googleapis.com/my_test_metric".

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::DeleteMetricDescriptorRequest.new

# Call the delete_metric_descriptor method.
result = client.delete_metric_descriptor request

# The returned object is of type Google::Protobuf::Empty.
p result

#get_metric_descriptor

def get_metric_descriptor(request, options = nil) -> ::Google::Api::MetricDescriptor
def get_metric_descriptor(name: nil) -> ::Google::Api::MetricDescriptor

Gets a single metric descriptor.

Overloads
def get_metric_descriptor(request, options = nil) -> ::Google::Api::MetricDescriptor
Pass arguments to get_metric_descriptor via a request object, either of type GetMetricDescriptorRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::GetMetricDescriptorRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_metric_descriptor(name: nil) -> ::Google::Api::MetricDescriptor
Pass arguments to get_metric_descriptor via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The metric descriptor on which to execute the request. The format is:

    projects/[PROJECT_ID_OR_NUMBER]/metricDescriptors/[METRIC_ID]
    

    An example value of [METRIC_ID] is "compute.googleapis.com/instance/disk/read_bytes_count".

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::GetMetricDescriptorRequest.new

# Call the get_metric_descriptor method.
result = client.get_metric_descriptor request

# The returned object is of type Google::Api::MetricDescriptor.
p result

#get_monitored_resource_descriptor

def get_monitored_resource_descriptor(request, options = nil) -> ::Google::Api::MonitoredResourceDescriptor
def get_monitored_resource_descriptor(name: nil) -> ::Google::Api::MonitoredResourceDescriptor

Gets a single monitored resource descriptor.

Overloads
def get_monitored_resource_descriptor(request, options = nil) -> ::Google::Api::MonitoredResourceDescriptor
Pass arguments to get_monitored_resource_descriptor via a request object, either of type GetMonitoredResourceDescriptorRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::GetMonitoredResourceDescriptorRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_monitored_resource_descriptor(name: nil) -> ::Google::Api::MonitoredResourceDescriptor
Pass arguments to get_monitored_resource_descriptor via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The monitored resource descriptor to get. The format is:

    projects/[PROJECT_ID_OR_NUMBER]/monitoredResourceDescriptors/[RESOURCE_TYPE]
    

    The [RESOURCE_TYPE] is a predefined type, such as cloudsql_database.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::GetMonitoredResourceDescriptorRequest.new

# Call the get_monitored_resource_descriptor method.
result = client.get_monitored_resource_descriptor request

# The returned object is of type Google::Api::MonitoredResourceDescriptor.
p result

#initialize

def initialize() { |config| ... } -> Client

Create a new MetricService client object.

Yields
  • (config) — Configure the MetricService client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Monitoring::V3::MetricService::Client.new do |config|
  config.timeout = 10.0
end

#list_metric_descriptors

def list_metric_descriptors(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Api::MetricDescriptor>
def list_metric_descriptors(name: nil, filter: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Api::MetricDescriptor>

Lists metric descriptors that match a filter.

Overloads
def list_metric_descriptors(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Api::MetricDescriptor>
Pass arguments to list_metric_descriptors via a request object, either of type ListMetricDescriptorsRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::ListMetricDescriptorsRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_metric_descriptors(name: nil, filter: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Api::MetricDescriptor>
Pass arguments to list_metric_descriptors via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) —

    Required. The project on which to execute the request. The format is:

    projects/[PROJECT_ID_OR_NUMBER]
    
  • filter (::String) —

    If this field is empty, all custom and system-defined metric descriptors are returned. Otherwise, the filter specifies which metric descriptors are to be returned. For example, the following filter matches all custom metrics:

    metric.type = starts_with("custom.googleapis.com/")
    
  • page_size (::Integer) — A positive number that is the maximum number of results to return. The default and maximum value is 10,000. If a page_size <= 0 or > 10,000 is submitted, will instead return a maximum of 10,000 results.
  • page_token (::String) — If this field is not empty then it must contain the nextPageToken value returned by a previous call to this method. Using this field causes the method to return additional results from the previous method call.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::ListMetricDescriptorsRequest.new

# Call the list_metric_descriptors method.
result = client.list_metric_descriptors request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Api::MetricDescriptor.
  p item
end

#list_monitored_resource_descriptors

def list_monitored_resource_descriptors(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Api::MonitoredResourceDescriptor>
def list_monitored_resource_descriptors(name: nil, filter: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Api::MonitoredResourceDescriptor>

Lists monitored resource descriptors that match a filter.

Overloads
def list_monitored_resource_descriptors(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Api::MonitoredResourceDescriptor>
Pass arguments to list_monitored_resource_descriptors via a request object, either of type ListMonitoredResourceDescriptorsRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::ListMonitoredResourceDescriptorsRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_monitored_resource_descriptors(name: nil, filter: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Api::MonitoredResourceDescriptor>
Pass arguments to list_monitored_resource_descriptors via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) —

    Required. The project on which to execute the request. The format is:

    projects/[PROJECT_ID_OR_NUMBER]
    
  • filter (::String) —

    An optional filter describing the descriptors to be returned. The filter can reference the descriptor's type and labels. For example, the following filter returns only Google Compute Engine descriptors that have an id label:

    resource.type = starts_with("gce_") AND resource.label:id
    
  • page_size (::Integer) — A positive number that is the maximum number of results to return.
  • page_token (::String) — If this field is not empty then it must contain the nextPageToken value returned by a previous call to this method. Using this field causes the method to return additional results from the previous method call.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::ListMonitoredResourceDescriptorsRequest.new

# Call the list_monitored_resource_descriptors method.
result = client.list_monitored_resource_descriptors request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Api::MonitoredResourceDescriptor.
  p item
end

#list_time_series

def list_time_series(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Monitoring::V3::TimeSeries>
def list_time_series(name: nil, filter: nil, interval: nil, aggregation: nil, secondary_aggregation: nil, order_by: nil, view: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Monitoring::V3::TimeSeries>

Lists time series that match a filter.

Overloads
def list_time_series(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Monitoring::V3::TimeSeries>
Pass arguments to list_time_series via a request object, either of type ListTimeSeriesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Monitoring::V3::ListTimeSeriesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_time_series(name: nil, filter: nil, interval: nil, aggregation: nil, secondary_aggregation: nil, order_by: nil, view: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Monitoring::V3::TimeSeries>
Pass arguments to list_time_series via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) —

    Required. The project, organization or folder on which to execute the request. The format is:

    projects/[PROJECT_ID_OR_NUMBER]
    organizations/[ORGANIZATION_ID]
    folders/[FOLDER_ID]
    
  • filter (::String) —

    Required. A monitoring filter that specifies which time series should be returned. The filter must specify a single metric type, and can additionally specify metric labels and other information. For example:

    metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND
        metric.labels.instance_name = "my-instance-name"
    
  • interval (::Google::Cloud::Monitoring::V3::TimeInterval, ::Hash) — Required. The time interval for which results should be returned. Only time series that contain data points in the specified interval are included in the response.
  • aggregation (::Google::Cloud::Monitoring::V3::Aggregation, ::Hash) — Specifies the alignment of data points in individual time series as well as how to combine the retrieved time series across specified labels.

    By default (if no aggregation is explicitly specified), the raw time series data is returned.

  • secondary_aggregation (::Google::Cloud::Monitoring::V3::Aggregation, ::Hash) — Apply a second aggregation after aggregation is applied. May only be specified if aggregation is specified.
  • order_by (::String) — Unsupported: must be left blank. The points in each time series are currently returned in reverse time order (most recent to oldest).
  • view (::Google::Cloud::Monitoring::V3::ListTimeSeriesRequest::TimeSeriesView) — Required. Specifies which information is returned about the time series.
  • page_size (::Integer) — A positive number that is the maximum number of results to return. If page_size is empty or more than 100,000 results, the effective page_size is 100,000 results. If view is set to FULL, this is the maximum number of Points returned. If view is set to HEADERS, this is the maximum number of TimeSeries returned.
  • page_token (::String) — If this field is not empty then it must contain the nextPageToken value returned by a previous call to this method. Using this field causes the method to return additional results from the previous method call.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/monitoring/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Monitoring::V3::MetricService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Monitoring::V3::ListTimeSeriesRequest.new

# Call the list_time_series method.
result = client.list_time_series request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Monitoring::V3::TimeSeries.
  p item
end

#universe_domain

def universe_domain() -> String

The effective universe domain

Returns
  • (String)