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