diff --git a/README.md b/README.md index 613e6eb..3c9ae72 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,11 @@ Metrics | `azurerm_quota` | Quota | Azure RM quota details (readable name, scope, ...) | | `azurerm_quota_current` | Quota | Azure RM quota current (current value) | | `azurerm_quota_limit` | Quota | Azure RM quota limit (maximum limited value) | -| `azurerm_vm_info` | Computing | Azure VM informations | -| `azurerm_vm_os` | Computing | Azure VM base image informations | +| `azurerm_vm_info` | Computing | Azure VM information | +| `azurerm_vm_os` | Computing | Azure VM base image information | +| `azurerm_vm_nic` | Computing | Azure VM network card information | +| `azurerm_vmss_info` | Computing | Azure VMSS base image information | +| `azurerm_vmss_capacity` | Computing | Azure VMSS capacity (number of instances) | | `azurerm_publicip_info` | Computing | Azure Public IPs details (subscriptionID, resourceGroup, ipAdress, ipVersion, ...) | | `azurerm_publicip_portscan_status` | Computing | Status of scanned ports (finished scan, elapsed time, updated timestamp) | | `azurerm_publicip_portscan_port` | Portscan | List of opend ports per IP | @@ -71,14 +74,14 @@ Metrics | `azurerm_eventhub_namespace_eventhub_status` | Eventhub | Eventhub namespace eventhub status (partitionCount, messageRetentionInDays) | | `azurerm_securitycenter_compliance` | Security | Azure SecurityCenter compliance status | | `azurerm_advisor_recommendation` | Security | Azure Adisor recommendations (eg. security findings) | -| `azurerm_resource_info` | Resource | Azure Resource informations | -| `azurerm_resource_health` | Health | Azure Resource health informations | -| `azurerm_storageaccount_info` | Storage | Azure StorageAccount informations | -| `azurerm_manageddisk_info` | Storage | Azure ManagedDisk informations | +| `azurerm_resource_info` | Resource | Azure Resource information | +| `azurerm_resource_health` | Health | Azure Resource health information | +| `azurerm_storageaccount_info` | Storage | Azure StorageAccount information | +| `azurerm_manageddisk_info` | Storage | Azure ManagedDisk information | | `azurerm_manageddisk_size` | Storage | Azure ManagedDisk size | -| `azurerm_manageddisk_status` | Storage | Azure ManagedDisk stats informations | +| `azurerm_manageddisk_status` | Storage | Azure ManagedDisk stats information | | `azurerm_iam_roleassignment_info` | IAM | Azure IAM RoleAssignment information | | `azurerm_iam_roledefinition_info` | IAM | Azure IAM RoleDefinition information | -| `azurerm_iam_principal_info` | IAM | Azure IAM Principal informations | -| `azurerm_graph_app_info` | Graph | AzureAD graph application informations | -| `azurerm_graph_app_credential` | Graph | AzureAD graph application credentials (create,expiry) informations | +| `azurerm_iam_principal_info` | IAM | Azure IAM Principal information | +| `azurerm_graph_app_info` | Graph | AzureAD graph application information | +| `azurerm_graph_app_credential` | Graph | AzureAD graph application credentials (create,expiry) information | diff --git a/metrics_azurerm_compute.go b/metrics_azurerm_compute.go index dfa8139..11bec5f 100644 --- a/metrics_azurerm_compute.go +++ b/metrics_azurerm_compute.go @@ -16,6 +16,9 @@ type MetricsCollectorAzureRmCompute struct { vm *prometheus.GaugeVec vmOs *prometheus.GaugeVec vmNic *prometheus.GaugeVec + + vmss *prometheus.GaugeVec + vmssCapacity *prometheus.GaugeVec } } @@ -42,6 +45,7 @@ func (m *MetricsCollectorAzureRmCompute) Setup(collector *CollectorGeneral) { azureResourceTags.prometheusLabels..., ), ) + prometheus.MustRegister(m.prometheus.vm) m.prometheus.vmOs = prometheus.NewGaugeVec( prometheus.GaugeOpts{ @@ -56,6 +60,8 @@ func (m *MetricsCollectorAzureRmCompute) Setup(collector *CollectorGeneral) { "imageVersion", }, ) + prometheus.MustRegister(m.prometheus.vmOs) + m.prometheus.vmNic = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "azurerm_vm_nic", @@ -67,19 +73,55 @@ func (m *MetricsCollectorAzureRmCompute) Setup(collector *CollectorGeneral) { "isPrimary", }, ) + prometheus.MustRegister(m.prometheus.vmNic) - prometheus.MustRegister(m.prometheus.vm) - prometheus.MustRegister(m.prometheus.vmOs) + m.prometheus.vmss = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "azurerm_vmss_info", + Help: "Azure ResourceManager VMSS", + }, + append( + []string{ + "resourceID", + "subscriptionID", + "location", + "resourceGroup", + "vmssName", + "vmssType", + "vmssProvisioningState", + }, + azureResourceTags.prometheusLabels..., + ), + ) + prometheus.MustRegister(m.prometheus.vmss) + + m.prometheus.vmssCapacity = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "azurerm_vmss_capacity", + Help: "Azure ResourceManager VMSS", + }, + []string{ + "resourceID", + "subscriptionID", + "location", + "resourceGroup", + "vmssName", + }, + ) + prometheus.MustRegister(m.prometheus.vmssCapacity) } func (m *MetricsCollectorAzureRmCompute) Reset() { m.prometheus.vm.Reset() m.prometheus.vmOs.Reset() m.prometheus.vmNic.Reset() + m.prometheus.vmss.Reset() + m.prometheus.vmssCapacity.Reset() } func (m *MetricsCollectorAzureRmCompute) Collect(ctx context.Context, logger *log.Entry, callback chan<- func(), subscription subscriptions.Subscription) { m.collectAzureVm(ctx, logger, callback, subscription) + m.collectAzureVmss(ctx, logger, callback, subscription) } func (m *MetricsCollectorAzureRmCompute) collectAzureVm(ctx context.Context, logger *log.Entry, callback chan<- func(), subscription subscriptions.Subscription) { @@ -149,3 +191,52 @@ func (m *MetricsCollectorAzureRmCompute) collectAzureVm(ctx context.Context, log nicMetric.GaugeSet(m.prometheus.vmNic) } } + +func (m *MetricsCollectorAzureRmCompute) collectAzureVmss(ctx context.Context, logger *log.Entry, callback chan<- func(), subscription subscriptions.Subscription) { + client := compute.NewVirtualMachineScaleSetsClient(*subscription.SubscriptionID) + client.Authorizer = AzureAuthorizer + + list, err := client.ListAllComplete(ctx) + + if err != nil { + logger.Panic(err) + } + + infoMetric := prometheusCommon.NewMetricsList() + capacityMetric := prometheusCommon.NewMetricsList() + + for list.NotDone() { + val := list.Value() + + infoLabels := prometheus.Labels{ + "resourceID": *val.ID, + "subscriptionID": *subscription.SubscriptionID, + "location": stringPtrToString(val.Location), + "resourceGroup": extractResourceGroupFromAzureId(*val.ID), + "vmssName": stringPtrToString(val.Name), + "vmssType": stringPtrToString(val.Type), + "vmssProvisioningState": stringPtrToString(val.ProvisioningState), + } + infoLabels = azureResourceTags.appendPrometheusLabel(infoLabels, val.Tags) + infoMetric.AddInfo(infoLabels) + + if val.Sku != nil && val.Sku.Capacity != nil { + capacityMetric.Add(prometheus.Labels{ + "resourceID": *val.ID, + "subscriptionID": *subscription.SubscriptionID, + "location": stringPtrToString(val.Location), + "resourceGroup": extractResourceGroupFromAzureId(*val.ID), + "vmssName": stringPtrToString(val.Name), + }, float64(*val.Sku.Capacity)) + } + + if list.NextWithContext(ctx) != nil { + break + } + } + + callback <- func() { + infoMetric.GaugeSet(m.prometheus.vmss) + capacityMetric.GaugeSet(m.prometheus.vmssCapacity) + } +}