...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-06-01-preview/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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // MetricsClient is the monitor Management Client
    19  type MetricsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewMetricsClient creates an instance of the MetricsClient client.
    24  func NewMetricsClient(subscriptionID string) MetricsClient {
    25  	return NewMetricsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewMetricsClientWithBaseURI creates an instance of the MetricsClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewMetricsClientWithBaseURI(baseURI string, subscriptionID string) MetricsClient {
    31  	return MetricsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // List **Lists the metric values for a resource**.
    35  // Parameters:
    36  // resourceURI - the identifier of the resource.
    37  // timespan - the timespan of the query. It is a string with the following format
    38  // 'startDateTime_ISO/endDateTime_ISO'.
    39  // interval - the interval (i.e. timegrain) of the query.
    40  // metricnames - the names of the metrics (comma separated) to retrieve. Special case: If a metricname itself
    41  // has a comma in it then use %2 to indicate it. Eg: 'Metric,Name1' should be **'Metric%2Name1'**
    42  // aggregation - the list of aggregation types (comma separated) to retrieve.
    43  // top - the maximum number of records to retrieve.
    44  // Valid only if $filter is specified.
    45  // Defaults to 10.
    46  // orderby - the aggregation to use for sorting results and the direction of the sort.
    47  // Only one order can be specified.
    48  // Examples: sum asc.
    49  // filter - the **$filter** is used to reduce the set of metric data returned. Example: Metric contains
    50  // 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
    51  // eq 'b1' or B eq 'b2' and C eq '*'** - Invalid variant: **$filter=A eq 'a1' and B eq 'b1' and C eq '*' or B =
    52  // 'b2'** This is invalid because the logical or operator cannot separate two different metadata names. -
    53  // Return all time series where A = a1, B = b1 and C = c1: **$filter=A eq 'a1' and B eq 'b1' and C eq 'c1'** -
    54  // Return all time series where A = a1 **$filter=A eq 'a1' and B eq '*' and C eq '*'**. Special case: When
    55  // dimension name or dimension value uses round brackets. Eg: When dimension name is **dim (test) 1** Instead
    56  // of using $filter= "dim (test) 1 eq '*' " use **$filter= "dim %2528test%2529 1 eq '*' "** When dimension name
    57  // is **dim (test) 3** and dimension value is **dim3 (test) val** Instead of using $filter= "dim (test) 3 eq
    58  // 'dim3 (test) val' " use **$filter= "dim %2528test%2529 3 eq 'dim3 %2528test%2529 val' "**
    59  // resultType - reduces the set of data collected. The syntax allowed depends on the operation. See the
    60  // operation's description for details.
    61  // metricnamespace - metric namespace to query metric definitions for.
    62  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) {
    63  	if tracing.IsEnabled() {
    64  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricsClient.List")
    65  		defer func() {
    66  			sc := -1
    67  			if result.Response.Response != nil {
    68  				sc = result.Response.Response.StatusCode
    69  			}
    70  			tracing.EndSpan(ctx, sc, err)
    71  		}()
    72  	}
    73  	if err := validation.Validate([]validation.Validation{
    74  		{TargetValue: resourceURI,
    75  			Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    76  		return result, validation.NewError("insights.MetricsClient", "List", err.Error())
    77  	}
    78  
    79  	req, err := client.ListPreparer(ctx, resourceURI, timespan, interval, metricnames, aggregation, top, orderby, filter, resultType, metricnamespace)
    80  	if err != nil {
    81  		err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", nil, "Failure preparing request")
    82  		return
    83  	}
    84  
    85  	resp, err := client.ListSender(req)
    86  	if err != nil {
    87  		result.Response = autorest.Response{Response: resp}
    88  		err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", resp, "Failure sending request")
    89  		return
    90  	}
    91  
    92  	result, err = client.ListResponder(resp)
    93  	if err != nil {
    94  		err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", resp, "Failure responding to request")
    95  		return
    96  	}
    97  
    98  	return
    99  }
   100  
   101  // ListPreparer prepares the List request.
   102  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) {
   103  	pathParameters := map[string]interface{}{
   104  		"resourceUri": resourceURI,
   105  	}
   106  
   107  	const APIVersion = "2018-01-01"
   108  	queryParameters := map[string]interface{}{
   109  		"api-version": APIVersion,
   110  	}
   111  	if len(timespan) > 0 {
   112  		queryParameters["timespan"] = autorest.Encode("query", timespan)
   113  	}
   114  	if interval != nil {
   115  		queryParameters["interval"] = autorest.Encode("query", *interval)
   116  	}
   117  	if len(metricnames) > 0 {
   118  		queryParameters["metricnames"] = autorest.Encode("query", metricnames)
   119  	}
   120  	if len(aggregation) > 0 {
   121  		queryParameters["aggregation"] = autorest.Encode("query", aggregation)
   122  	}
   123  	if top != nil {
   124  		queryParameters["top"] = autorest.Encode("query", *top)
   125  	}
   126  	if len(orderby) > 0 {
   127  		queryParameters["orderby"] = autorest.Encode("query", orderby)
   128  	}
   129  	if len(filter) > 0 {
   130  		queryParameters["$filter"] = autorest.Encode("query", filter)
   131  	}
   132  	if len(string(resultType)) > 0 {
   133  		queryParameters["resultType"] = autorest.Encode("query", resultType)
   134  	}
   135  	if len(metricnamespace) > 0 {
   136  		queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
   137  	}
   138  
   139  	preparer := autorest.CreatePreparer(
   140  		autorest.AsGet(),
   141  		autorest.WithBaseURL(client.BaseURI),
   142  		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/metrics", pathParameters),
   143  		autorest.WithQueryParameters(queryParameters))
   144  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   145  }
   146  
   147  // ListSender sends the List request. The method will close the
   148  // http.Response Body if it receives an error.
   149  func (client MetricsClient) ListSender(req *http.Request) (*http.Response, error) {
   150  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   151  }
   152  
   153  // ListResponder handles the response to the List request. The method always
   154  // closes the http.Response Body.
   155  func (client MetricsClient) ListResponder(resp *http.Response) (result Response, err error) {
   156  	err = autorest.Respond(
   157  		resp,
   158  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   159  		autorest.ByUnmarshallingJSON(&result),
   160  		autorest.ByClosing())
   161  	result.Response = autorest.Response{Response: resp}
   162  	return
   163  }
   164  

View as plain text