Skip to content

Commit 53ce2ff

Browse files
committed
Fix wrong quota values
fixes #83 Azure quota names are not unique, so we use localized name as label everywhere Signed-off-by: Markus Blaschke <[email protected]>
1 parent 21f5906 commit 53ce2ff

File tree

1 file changed

+21
-77
lines changed

1 file changed

+21
-77
lines changed

metrics_azurerm_quota.go

Lines changed: 21 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (m *MetricsCollectorAzureRmQuota) Setup(collector *collector.Collector) {
6060
"provider",
6161
"scope",
6262
"quota",
63+
"quotaName",
6364
},
6465
)
6566

@@ -74,6 +75,7 @@ func (m *MetricsCollectorAzureRmQuota) Setup(collector *collector.Collector) {
7475
"provider",
7576
"scope",
7677
"quota",
78+
"quotaName",
7779
},
7880
)
7981

@@ -88,6 +90,7 @@ func (m *MetricsCollectorAzureRmQuota) Setup(collector *collector.Collector) {
8890
"provider",
8991
"scope",
9092
"quota",
93+
"quotaName",
9194
},
9295
)
9396

@@ -190,29 +193,19 @@ func (m *MetricsCollectorAzureRmQuota) collectAuthorizationUsage(subscription *a
190193
}{}
191194

192195
if err := runtime.UnmarshalAsJSON(resp, &result); err == nil {
193-
quotaName := "RoleAssignments"
194-
quotaNameLocalized := "Role Assignments"
195196
currentValue := result.RoleAssignmentsCurrentCount
196197
limitValue := result.RoleAssignmentsLimit
197198

198-
infoLabels := prometheus.Labels{
199-
"subscriptionID": to.StringLower(subscription.SubscriptionID),
200-
"location": "",
201-
"provider": "microsoft.authorization",
202-
"scope": "authorization",
203-
"quota": quotaName,
204-
"quotaName": quotaNameLocalized,
205-
}
206-
207199
labels := prometheus.Labels{
208200
"subscriptionID": to.StringLower(subscription.SubscriptionID),
209201
"location": "",
210202
"provider": "microsoft.authorization",
211203
"scope": "authorization",
212-
"quota": quotaName,
204+
"quota": "RoleAssignments",
205+
"quotaName": "Role Assignments",
213206
}
214207

215-
quotaMetric.Add(infoLabels, 1)
208+
quotaMetric.Add(labels, 1)
216209
quotaCurrentMetric.Add(labels, currentValue)
217210
quotaLimitMetric.Add(labels, limitValue)
218211
if limitValue != 0 {
@@ -252,27 +245,18 @@ func (m *MetricsCollectorAzureRmQuota) collectAuthorizationUsage(subscription *a
252245
// }
253246
//
254247
// for _, resourceUsage := range result.Value {
255-
// quotaName := to.String(resourceUsage.Properties.Name.Value)
256-
// quotaNameLocalized := to.String(resourceUsage.Properties.Name.LocalizedValue)
257248
// currentValue := float64(to.Number(resourceUsage.Properties.Usages.Value))
258249
// limitValue := float64(to.Number(resourceUsage.Properties.Usages.Limit))
259250
//
260-
// infoLabels := prometheus.Labels{
261-
// "subscriptionID": to.StringLower(subscription.SubscriptionID),
262-
// "location": strings.ToLower(location),
263-
// "scope": provider,
264-
// "quota": quotaName,
265-
// "quotaName": quotaNameLocalized,
266-
// }
267-
//
268251
// labels := prometheus.Labels{
269252
// "subscriptionID": to.StringLower(subscription.SubscriptionID),
270253
// "location": strings.ToLower(location),
271254
// "scope": provider,
272-
// "quota": quotaName,
255+
// "quota": to.String(resourceUsage.Properties.Name.Value),
256+
// "quotaName": to.String(resourceUsage.Properties.Name.LocalizedValue),
273257
// }
274258
//
275-
// quotaMetric.Add(infoLabels, 1)
259+
// quotaMetric.Add(labels, 1)
276260
// quotaCurrentMetric.Add(labels, currentValue)
277261
// quotaLimitMetric.Add(labels, limitValue)
278262
// if limitValue != 0 {
@@ -309,29 +293,19 @@ func (m *MetricsCollectorAzureRmQuota) collectAzureComputeUsage(subscription *ar
309293
}
310294

311295
for _, resourceUsage := range result.Value {
312-
quotaName := to.String(resourceUsage.Name.Value)
313-
quotaNameLocalized := to.String(resourceUsage.Name.LocalizedValue)
314296
currentValue := float64(to.Number(resourceUsage.CurrentValue))
315297
limitValue := float64(to.Number(resourceUsage.Limit))
316298

317-
infoLabels := prometheus.Labels{
318-
"subscriptionID": to.StringLower(subscription.SubscriptionID),
319-
"location": strings.ToLower(location),
320-
"provider": "microsoft.compute",
321-
"scope": "compute",
322-
"quota": quotaName,
323-
"quotaName": quotaNameLocalized,
324-
}
325-
326299
labels := prometheus.Labels{
327300
"subscriptionID": to.StringLower(subscription.SubscriptionID),
328301
"location": strings.ToLower(location),
329302
"provider": "microsoft.compute",
330303
"scope": "compute",
331-
"quota": quotaName,
304+
"quota": to.String(resourceUsage.Name.Value),
305+
"quotaName": to.String(resourceUsage.Name.LocalizedValue),
332306
}
333307

334-
quotaMetric.Add(infoLabels, 1)
308+
quotaMetric.Add(labels, 1)
335309
quotaCurrentMetric.Add(labels, currentValue)
336310
quotaLimitMetric.Add(labels, limitValue)
337311
if limitValue != 0 {
@@ -368,29 +342,19 @@ func (m *MetricsCollectorAzureRmQuota) collectAzureNetworkUsage(subscription *ar
368342
}
369343

370344
for _, resourceUsage := range result.Value {
371-
quotaName := to.String(resourceUsage.Name.Value)
372-
quotaNameLocalized := to.String(resourceUsage.Name.LocalizedValue)
373345
currentValue := float64(to.Number(resourceUsage.CurrentValue))
374346
limitValue := float64(to.Number(resourceUsage.Limit))
375347

376-
infoLabels := prometheus.Labels{
377-
"subscriptionID": to.StringLower(subscription.SubscriptionID),
378-
"location": strings.ToLower(location),
379-
"provider": "microsoft.network",
380-
"scope": "network",
381-
"quota": quotaName,
382-
"quotaName": quotaNameLocalized,
383-
}
384-
385348
labels := prometheus.Labels{
386349
"subscriptionID": to.StringLower(subscription.SubscriptionID),
387350
"location": strings.ToLower(location),
388351
"provider": "microsoft.network",
389352
"scope": "network",
390-
"quota": quotaName,
353+
"quota": to.String(resourceUsage.Name.Value),
354+
"quotaName": to.String(resourceUsage.Name.LocalizedValue),
391355
}
392356

393-
quotaMetric.Add(infoLabels, 1)
357+
quotaMetric.Add(labels, 1)
394358
quotaCurrentMetric.Add(labels, currentValue)
395359
quotaLimitMetric.Add(labels, limitValue)
396360
if limitValue != 0 {
@@ -427,29 +391,19 @@ func (m *MetricsCollectorAzureRmQuota) collectAzureStorageUsage(subscription *ar
427391
}
428392

429393
for _, resourceUsage := range result.Value {
430-
quotaName := to.String(resourceUsage.Name.Value)
431-
quotaNameLocalized := to.String(resourceUsage.Name.LocalizedValue)
432394
currentValue := float64(to.Number(resourceUsage.CurrentValue))
433395
limitValue := float64(to.Number(resourceUsage.Limit))
434396

435-
infoLabels := prometheus.Labels{
436-
"subscriptionID": to.StringLower(subscription.SubscriptionID),
437-
"location": strings.ToLower(location),
438-
"provider": "microsoft.storage",
439-
"scope": "storage",
440-
"quota": quotaName,
441-
"quotaName": quotaNameLocalized,
442-
}
443-
444397
labels := prometheus.Labels{
445398
"subscriptionID": to.StringLower(subscription.SubscriptionID),
446399
"location": strings.ToLower(location),
447400
"provider": "microsoft.storage",
448401
"scope": "storage",
449-
"quota": quotaName,
402+
"quota": to.String(resourceUsage.Name.Value),
403+
"quotaName": to.String(resourceUsage.Name.LocalizedValue),
450404
}
451405

452-
quotaMetric.Add(infoLabels, 1)
406+
quotaMetric.Add(labels, 1)
453407
quotaCurrentMetric.Add(labels, currentValue)
454408
quotaLimitMetric.Add(labels, limitValue)
455409
if limitValue != 0 {
@@ -486,29 +440,19 @@ func (m *MetricsCollectorAzureRmQuota) collectAzureMachineLearningUsage(subscrip
486440
}
487441

488442
for _, resourceUsage := range result.Value {
489-
quotaName := to.String(resourceUsage.Name.Value)
490-
quotaNameLocalized := to.String(resourceUsage.Name.LocalizedValue)
491443
currentValue := float64(to.Number(resourceUsage.CurrentValue))
492444
limitValue := float64(to.Number(resourceUsage.Limit))
493445

494-
infoLabels := prometheus.Labels{
495-
"subscriptionID": to.StringLower(subscription.SubscriptionID),
496-
"location": strings.ToLower(location),
497-
"provider": "microsoft.machinelearningservices",
498-
"scope": "machinelearningservices",
499-
"quota": quotaName,
500-
"quotaName": quotaNameLocalized,
501-
}
502-
503446
labels := prometheus.Labels{
504447
"subscriptionID": to.StringLower(subscription.SubscriptionID),
505448
"location": strings.ToLower(location),
506449
"provider": "microsoft.machinelearningservices",
507450
"scope": "machinelearningservices",
508-
"quota": quotaName,
451+
"quota": to.String(resourceUsage.Name.Value),
452+
"quotaName": to.String(resourceUsage.Name.LocalizedValue),
509453
}
510454

511-
quotaMetric.Add(infoLabels, 1)
455+
quotaMetric.Add(labels, 1)
512456
quotaCurrentMetric.Add(labels, currentValue)
513457
quotaLimitMetric.Add(labels, limitValue)
514458
if limitValue != 0 {

0 commit comments

Comments
 (0)