Skip to content

Commit

Permalink
add additional labels to azurerm_resource_info and azurerm_resourcegr…
Browse files Browse the repository at this point in the history
…oup_info

azurerm_resource_info:
- add label resourceName
- add label location
- add label provisioningState

azurerm_resourcegroup_info:
- add label provisioningState

Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Oct 11, 2021
1 parent 367cb2f commit a5ae429
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions metrics_azurerm_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
prometheusCommon "github.com/webdevops/go-prometheus-common"
"strings"
)

type MetricsCollectorAzureRmResources struct {
Expand All @@ -30,9 +31,12 @@ func (m *MetricsCollectorAzureRmResources) Setup(collector *CollectorGeneral) {
append(
[]string{
"resourceID",
"resourceName",
"subscriptionID",
"resourceGroup",
"provider",
"location",
"provisioningState",
},
azureResourceTags.prometheusLabels...,
),
Expand All @@ -50,6 +54,7 @@ func (m *MetricsCollectorAzureRmResources) Setup(collector *CollectorGeneral) {
"subscriptionID",
"resourceGroup",
"location",
"provisioningState",
},
azureResourceGroupTags.prometheusLabels...,
),
Expand Down Expand Up @@ -82,10 +87,11 @@ func (m *MetricsCollectorAzureRmResources) collectAzureResourceGroup(ctx context

for _, item := range *resourceGroupResult.Response().Value {
infoLabels := azureResourceGroupTags.appendPrometheusLabel(prometheus.Labels{
"resourceID": toResourceId(item.ID),
"subscriptionID": to.String(subscription.SubscriptionID),
"resourceGroup": to.String(item.Name),
"location": to.String(item.Location),
"resourceID": toResourceId(item.ID),
"subscriptionID": to.String(subscription.SubscriptionID),
"resourceGroup": to.String(item.Name),
"location": to.String(item.Location),
"provisioningState": strings.ToLower(to.String(item.Properties.ProvisioningState)),
}, item.Tags)
infoMetric.AddInfo(infoLabels)
}
Expand All @@ -100,7 +106,7 @@ func (m *MetricsCollectorAzureRmResources) collectAzureResources(ctx context.Con
client.Authorizer = AzureAuthorizer
client.ResponseInspector = azureResponseInspector(&subscription)

list, err := client.ListComplete(ctx, "", "", nil)
list, err := client.ListComplete(ctx, "", "createdTime,changedTime,provisioningState", nil)

if err != nil {
logger.Panic(err)
Expand All @@ -112,10 +118,13 @@ func (m *MetricsCollectorAzureRmResources) collectAzureResources(ctx context.Con
val := list.Value()

infoLabels := prometheus.Labels{
"subscriptionID": to.String(subscription.SubscriptionID),
"resourceID": toResourceId(val.ID),
"resourceGroup": extractResourceGroupFromAzureId(to.String(val.ID)),
"provider": extractProviderFromAzureId(to.String(val.ID)),
"subscriptionID": to.String(subscription.SubscriptionID),
"resourceID": toResourceId(val.ID),
"resourceName": to.String(val.Name),
"resourceGroup": extractResourceGroupFromAzureId(to.String(val.ID)),
"provider": extractProviderFromAzureId(to.String(val.ID)),
"location": to.String(val.Location),
"provisioningState": strings.ToLower(to.String(val.ProvisioningState)),
}
infoLabels = azureResourceTags.appendPrometheusLabel(infoLabels, val.Tags)
resourceMetric.AddInfo(infoLabels)
Expand Down

0 comments on commit a5ae429

Please sign in to comment.