Skip to content

Commit

Permalink
add basic vmss information
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
  • Loading branch information
mblaschke committed Nov 24, 2020
1 parent 9cd8632 commit b66dbe1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 12 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
95 changes: 93 additions & 2 deletions metrics_azurerm_compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type MetricsCollectorAzureRmCompute struct {
vm *prometheus.GaugeVec
vmOs *prometheus.GaugeVec
vmNic *prometheus.GaugeVec

vmss *prometheus.GaugeVec
vmssCapacity *prometheus.GaugeVec
}
}

Expand All @@ -42,6 +45,7 @@ func (m *MetricsCollectorAzureRmCompute) Setup(collector *CollectorGeneral) {
azureResourceTags.prometheusLabels...,
),
)
prometheus.MustRegister(m.prometheus.vm)

m.prometheus.vmOs = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand All @@ -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",
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit b66dbe1

Please sign in to comment.