# encoding: utf-8
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
module Azure::Monitor::Mgmt::V2018_01_01
#
# Monitor Management Client
#
class Metrics
include MsRestAzure
#
# Creates and initializes a new instance of the Metrics class.
# @param client service class for accessing basic functionality.
#
def initialize(client)
@client = client
end
# @return [MonitorManagementClient] reference to the MonitorManagementClient
attr_reader :client
#
# **Lists the metric values for a resource**.
#
# @param resource_uri [String] The identifier of the resource.
# @param timespan [String] The timespan of the query. It is a string with the
# following format 'startDateTime_ISO/endDateTime_ISO'.
# @param interval [Duration] The interval (i.e. timegrain) of the query.
# @param metricnames [String] The names of the metrics (comma separated) to
# retrieve.
# @param aggregation [String] The list of aggregation types (comma separated)
# to retrieve.
# @param top [Integer] The maximum number of records to retrieve.
# Valid only if $filter is specified.
# Defaults to 10.
# @param orderby [String] The aggregation to use for sorting results and the
# direction of the sort.
# Only one order can be specified.
# Examples: sum asc.
# @param filter [String] The **$filter** is used to reduce the set of metric
# data returned.
Example:
Metric contains metadata A, B and C.
-
# Return all time series of C where A = a1 and B = b1 or b2
**$filter=A eq
# ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**
- Invalid
# variant:
**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B =
# ‘b2’**
This is invalid because the logical or operator cannot separate two
# different metadata names.
- Return all time series where A = a1, B = b1
# and C = c1:
**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’**
- Return
# all time series where A = a1
**$filter=A eq ‘a1’ and B eq ‘*’ and C eq
# ‘*’**.
# @param result_type [ResultType] Reduces the set of data collected. The syntax
# allowed depends on the operation. See the operation's description for
# details. Possible values include: 'Data', 'Metadata'
# @param metricnamespace [String] Metric namespace to query metric definitions
# for.
# @param custom_headers [Hash{String => String}] A hash of custom headers that
# will be added to the HTTP request.
#
# @return [Response] operation results.
#
def list(resource_uri, timespan:nil, interval:nil, metricnames:nil, aggregation:nil, top:nil, orderby:nil, filter:nil, result_type:nil, metricnamespace:nil, custom_headers:nil)
response = list_async(resource_uri, timespan:timespan, interval:interval, metricnames:metricnames, aggregation:aggregation, top:top, orderby:orderby, filter:filter, result_type:result_type, metricnamespace:metricnamespace, custom_headers:custom_headers).value!
response.body unless response.nil?
end
#
# **Lists the metric values for a resource**.
#
# @param resource_uri [String] The identifier of the resource.
# @param timespan [String] The timespan of the query. It is a string with the
# following format 'startDateTime_ISO/endDateTime_ISO'.
# @param interval [Duration] The interval (i.e. timegrain) of the query.
# @param metricnames [String] The names of the metrics (comma separated) to
# retrieve.
# @param aggregation [String] The list of aggregation types (comma separated)
# to retrieve.
# @param top [Integer] The maximum number of records to retrieve.
# Valid only if $filter is specified.
# Defaults to 10.
# @param orderby [String] The aggregation to use for sorting results and the
# direction of the sort.
# Only one order can be specified.
# Examples: sum asc.
# @param filter [String] The **$filter** is used to reduce the set of metric
# data returned.
Example:
Metric contains metadata A, B and C.
-
# Return all time series of C where A = a1 and B = b1 or b2
**$filter=A eq
# ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**
- Invalid
# variant:
**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B =
# ‘b2’**
This is invalid because the logical or operator cannot separate two
# different metadata names.
- Return all time series where A = a1, B = b1
# and C = c1:
**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’**
- Return
# all time series where A = a1
**$filter=A eq ‘a1’ and B eq ‘*’ and C eq
# ‘*’**.
# @param result_type [ResultType] Reduces the set of data collected. The syntax
# allowed depends on the operation. See the operation's description for
# details. Possible values include: 'Data', 'Metadata'
# @param metricnamespace [String] Metric namespace to query metric definitions
# for.
# @param custom_headers [Hash{String => String}] A hash of custom headers that
# will be added to the HTTP request.
#
# @return [MsRestAzure::AzureOperationResponse] HTTP response information.
#
def list_with_http_info(resource_uri, timespan:nil, interval:nil, metricnames:nil, aggregation:nil, top:nil, orderby:nil, filter:nil, result_type:nil, metricnamespace:nil, custom_headers:nil)
list_async(resource_uri, timespan:timespan, interval:interval, metricnames:metricnames, aggregation:aggregation, top:top, orderby:orderby, filter:filter, result_type:result_type, metricnamespace:metricnamespace, custom_headers:custom_headers).value!
end
#
# **Lists the metric values for a resource**.
#
# @param resource_uri [String] The identifier of the resource.
# @param timespan [String] The timespan of the query. It is a string with the
# following format 'startDateTime_ISO/endDateTime_ISO'.
# @param interval [Duration] The interval (i.e. timegrain) of the query.
# @param metricnames [String] The names of the metrics (comma separated) to
# retrieve.
# @param aggregation [String] The list of aggregation types (comma separated)
# to retrieve.
# @param top [Integer] The maximum number of records to retrieve.
# Valid only if $filter is specified.
# Defaults to 10.
# @param orderby [String] The aggregation to use for sorting results and the
# direction of the sort.
# Only one order can be specified.
# Examples: sum asc.
# @param filter [String] The **$filter** is used to reduce the set of metric
# data returned.
Example:
Metric contains metadata A, B and C.
-
# Return all time series of C where A = a1 and B = b1 or b2
**$filter=A eq
# ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**
- Invalid
# variant:
**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B =
# ‘b2’**
This is invalid because the logical or operator cannot separate two
# different metadata names.
- Return all time series where A = a1, B = b1
# and C = c1:
**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’**
- Return
# all time series where A = a1
**$filter=A eq ‘a1’ and B eq ‘*’ and C eq
# ‘*’**.
# @param result_type [ResultType] Reduces the set of data collected. The syntax
# allowed depends on the operation. See the operation's description for
# details. Possible values include: 'Data', 'Metadata'
# @param metricnamespace [String] Metric namespace to query metric definitions
# for.
# @param [Hash{String => String}] A hash of custom headers that will be added
# to the HTTP request.
#
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
#
def list_async(resource_uri, timespan:nil, interval:nil, metricnames:nil, aggregation:nil, top:nil, orderby:nil, filter:nil, result_type:nil, metricnamespace:nil, custom_headers:nil)
fail ArgumentError, 'resource_uri is nil' if resource_uri.nil?
fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
request_headers = {}
request_headers['Content-Type'] = 'application/json; charset=utf-8'
# Set Headers
request_headers['x-ms-client-request-id'] = SecureRandom.uuid
request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
path_template = '{resourceUri}/providers/microsoft.insights/metrics'
request_url = @base_url || @client.base_url
options = {
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
skip_encoding_path_params: {'resourceUri' => resource_uri},
query_params: {'timespan' => timespan,'interval' => interval,'metricnames' => metricnames,'aggregation' => aggregation,'top' => top,'orderby' => orderby,'$filter' => filter,'resultType' => result_type,'api-version' => @client.api_version,'metricnamespace' => metricnamespace},
headers: request_headers.merge(custom_headers || {}),
base_url: request_url
}
promise = @client.make_request_async(:get, path_template, options)
promise = promise.then do |result|
http_response = result.response
status_code = http_response.status
response_content = http_response.body
unless status_code == 200
error_model = JSON.load(response_content)
fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
end
result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
# Deserialize Response
if status_code == 200
begin
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
result_mapper = Azure::Monitor::Mgmt::V2018_01_01::Models::Response.mapper()
result.body = @client.deserialize(result_mapper, parsed_response)
rescue Exception => e
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
end
end
result
end
promise.execute
end
end
end