...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights/metrics.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights

     1  package insights
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // MetricsClient is the monitor Management Client
    18  type MetricsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewMetricsClient creates an instance of the MetricsClient client.
    23  func NewMetricsClient(subscriptionID string) MetricsClient {
    24  	return NewMetricsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewMetricsClientWithBaseURI creates an instance of the MetricsClient client using a custom endpoint.  Use this when
    28  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewMetricsClientWithBaseURI(baseURI string, subscriptionID string) MetricsClient {
    30  	return MetricsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // List **Lists the metric values for a resource**.
    34  // Parameters:
    35  // resourceURI - the identifier of the resource.
    36  // timespan - the timespan of the query. It is a string with the following format
    37  // 'startDateTime_ISO/endDateTime_ISO'.
    38  // interval - the interval (i.e. timegrain) of the query.
    39  // metricnames - the names of the metrics (comma separated) to retrieve.
    40  // aggregation - the list of aggregation types (comma separated) to retrieve.
    41  // top - the maximum number of records to retrieve.
    42  // Valid only if $filter is specified.
    43  // Defaults to 10.
    44  // orderby - the aggregation to use for sorting results and the direction of the sort.
    45  // Only one order can be specified.
    46  // Examples: sum asc.
    47  // filter - the **$filter** is used to reduce the set of metric data returned.<br>Example:<br>Metric contains
    48  // metadata A, B and C.<br>- Return all time series of C where A = a1 and B = b1 or b2<br>**$filter=A eq ‘a1’
    49  // and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**<br>- Invalid variant:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C
    50  // eq ‘*’ or B = ‘b2’**<br>This is invalid because the logical or operator cannot separate two different
    51  // metadata names.<br>- Return all time series where A = a1, B = b1 and C = c1:<br>**$filter=A eq ‘a1’ and B eq
    52  // ‘b1’ and C eq ‘c1’**<br>- Return all time series where A = a1<br>**$filter=A eq ‘a1’ and B eq ‘*’ and C eq
    53  // ‘*’**.
    54  // resultType - reduces the set of data collected. The syntax allowed depends on the operation. See the
    55  // operation's description for details.
    56  // metricnamespace - metric namespace to query metric definitions for.
    57  func (client MetricsClient) List(ctx context.Context, resourceURI string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType ResultType, metricnamespace string) (result Response, err error) {
    58  	if tracing.IsEnabled() {
    59  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricsClient.List")
    60  		defer func() {
    61  			sc := -1
    62  			if result.Response.Response != nil {
    63  				sc = result.Response.Response.StatusCode
    64  			}
    65  			tracing.EndSpan(ctx, sc, err)
    66  		}()
    67  	}
    68  	req, err := client.ListPreparer(ctx, resourceURI, timespan, interval, metricnames, aggregation, top, orderby, filter, resultType, metricnamespace)
    69  	if err != nil {
    70  		err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", nil, "Failure preparing request")
    71  		return
    72  	}
    73  
    74  	resp, err := client.ListSender(req)
    75  	if err != nil {
    76  		result.Response = autorest.Response{Response: resp}
    77  		err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", resp, "Failure sending request")
    78  		return
    79  	}
    80  
    81  	result, err = client.ListResponder(resp)
    82  	if err != nil {
    83  		err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", resp, "Failure responding to request")
    84  		return
    85  	}
    86  
    87  	return
    88  }
    89  
    90  // ListPreparer prepares the List request.
    91  func (client MetricsClient) ListPreparer(ctx context.Context, resourceURI string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType ResultType, metricnamespace string) (*http.Request, error) {
    92  	pathParameters := map[string]interface{}{
    93  		"resourceUri": resourceURI,
    94  	}
    95  
    96  	const APIVersion = "2018-01-01"
    97  	queryParameters := map[string]interface{}{
    98  		"api-version": APIVersion,
    99  	}
   100  	if len(timespan) > 0 {
   101  		queryParameters["timespan"] = autorest.Encode("query", timespan)
   102  	}
   103  	if interval != nil {
   104  		queryParameters["interval"] = autorest.Encode("query", *interval)
   105  	}
   106  	if len(metricnames) > 0 {
   107  		queryParameters["metricnames"] = autorest.Encode("query", metricnames)
   108  	}
   109  	if len(aggregation) > 0 {
   110  		queryParameters["aggregation"] = autorest.Encode("query", aggregation)
   111  	}
   112  	if top != nil {
   113  		queryParameters["top"] = autorest.Encode("query", *top)
   114  	}
   115  	if len(orderby) > 0 {
   116  		queryParameters["orderby"] = autorest.Encode("query", orderby)
   117  	}
   118  	if len(filter) > 0 {
   119  		queryParameters["$filter"] = autorest.Encode("query", filter)
   120  	}
   121  	if len(string(resultType)) > 0 {
   122  		queryParameters["resultType"] = autorest.Encode("query", resultType)
   123  	}
   124  	if len(metricnamespace) > 0 {
   125  		queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
   126  	}
   127  
   128  	preparer := autorest.CreatePreparer(
   129  		autorest.AsGet(),
   130  		autorest.WithBaseURL(client.BaseURI),
   131  		autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/metrics", pathParameters),
   132  		autorest.WithQueryParameters(queryParameters))
   133  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   134  }
   135  
   136  // ListSender sends the List request. The method will close the
   137  // http.Response Body if it receives an error.
   138  func (client MetricsClient) ListSender(req *http.Request) (*http.Response, error) {
   139  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   140  }
   141  
   142  // ListResponder handles the response to the List request. The method always
   143  // closes the http.Response Body.
   144  func (client MetricsClient) ListResponder(resp *http.Response) (result Response, err error) {
   145  	err = autorest.Respond(
   146  		resp,
   147  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   148  		autorest.ByUnmarshallingJSON(&result),
   149  		autorest.ByClosing())
   150  	result.Response = autorest.Response{Response: resp}
   151  	return
   152  }
   153  

View as plain text