1 package insights
2
3
4
5
6
7
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
18 type MetricsClient struct {
19 BaseClient
20 }
21
22
23 func NewMetricsClient(subscriptionID string) MetricsClient {
24 return NewMetricsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewMetricsClientWithBaseURI(baseURI string, subscriptionID string) MetricsClient {
30 return MetricsClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
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
137
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
143
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