@@ -16,6 +16,9 @@ type MetricsCollectorAzureRmCompute struct {
1616 vm * prometheus.GaugeVec
1717 vmOs * prometheus.GaugeVec
1818 vmNic * prometheus.GaugeVec
19+
20+ vmss * prometheus.GaugeVec
21+ vmssCapacity * prometheus.GaugeVec
1922 }
2023}
2124
@@ -42,6 +45,7 @@ func (m *MetricsCollectorAzureRmCompute) Setup(collector *CollectorGeneral) {
4245 azureResourceTags .prometheusLabels ... ,
4346 ),
4447 )
48+ prometheus .MustRegister (m .prometheus .vm )
4549
4650 m .prometheus .vmOs = prometheus .NewGaugeVec (
4751 prometheus.GaugeOpts {
@@ -56,6 +60,8 @@ func (m *MetricsCollectorAzureRmCompute) Setup(collector *CollectorGeneral) {
5660 "imageVersion" ,
5761 },
5862 )
63+ prometheus .MustRegister (m .prometheus .vmOs )
64+
5965 m .prometheus .vmNic = prometheus .NewGaugeVec (
6066 prometheus.GaugeOpts {
6167 Name : "azurerm_vm_nic" ,
@@ -67,19 +73,55 @@ func (m *MetricsCollectorAzureRmCompute) Setup(collector *CollectorGeneral) {
6773 "isPrimary" ,
6874 },
6975 )
76+ prometheus .MustRegister (m .prometheus .vmNic )
7077
71- prometheus .MustRegister (m .prometheus .vm )
72- prometheus .MustRegister (m .prometheus .vmOs )
78+ m .prometheus .vmss = prometheus .NewGaugeVec (
79+ prometheus.GaugeOpts {
80+ Name : "azurerm_vmss_info" ,
81+ Help : "Azure ResourceManager VMSS" ,
82+ },
83+ append (
84+ []string {
85+ "resourceID" ,
86+ "subscriptionID" ,
87+ "location" ,
88+ "resourceGroup" ,
89+ "vmssName" ,
90+ "vmssType" ,
91+ "vmssProvisioningState" ,
92+ },
93+ azureResourceTags .prometheusLabels ... ,
94+ ),
95+ )
96+ prometheus .MustRegister (m .prometheus .vmss )
97+
98+ m .prometheus .vmssCapacity = prometheus .NewGaugeVec (
99+ prometheus.GaugeOpts {
100+ Name : "azurerm_vmss_capacity" ,
101+ Help : "Azure ResourceManager VMSS" ,
102+ },
103+ []string {
104+ "resourceID" ,
105+ "subscriptionID" ,
106+ "location" ,
107+ "resourceGroup" ,
108+ "vmssName" ,
109+ },
110+ )
111+ prometheus .MustRegister (m .prometheus .vmssCapacity )
73112}
74113
75114func (m * MetricsCollectorAzureRmCompute ) Reset () {
76115 m .prometheus .vm .Reset ()
77116 m .prometheus .vmOs .Reset ()
78117 m .prometheus .vmNic .Reset ()
118+ m .prometheus .vmss .Reset ()
119+ m .prometheus .vmssCapacity .Reset ()
79120}
80121
81122func (m * MetricsCollectorAzureRmCompute ) Collect (ctx context.Context , logger * log.Entry , callback chan <- func (), subscription subscriptions.Subscription ) {
82123 m .collectAzureVm (ctx , logger , callback , subscription )
124+ m .collectAzureVmss (ctx , logger , callback , subscription )
83125}
84126
85127func (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
149191 nicMetric .GaugeSet (m .prometheus .vmNic )
150192 }
151193}
194+
195+ func (m * MetricsCollectorAzureRmCompute ) collectAzureVmss (ctx context.Context , logger * log.Entry , callback chan <- func (), subscription subscriptions.Subscription ) {
196+ client := compute .NewVirtualMachineScaleSetsClient (* subscription .SubscriptionID )
197+ client .Authorizer = AzureAuthorizer
198+
199+ list , err := client .ListAllComplete (ctx )
200+
201+ if err != nil {
202+ logger .Panic (err )
203+ }
204+
205+ infoMetric := prometheusCommon .NewMetricsList ()
206+ capacityMetric := prometheusCommon .NewMetricsList ()
207+
208+ for list .NotDone () {
209+ val := list .Value ()
210+
211+ infoLabels := prometheus.Labels {
212+ "resourceID" : * val .ID ,
213+ "subscriptionID" : * subscription .SubscriptionID ,
214+ "location" : stringPtrToString (val .Location ),
215+ "resourceGroup" : extractResourceGroupFromAzureId (* val .ID ),
216+ "vmssName" : stringPtrToString (val .Name ),
217+ "vmssType" : stringPtrToString (val .Type ),
218+ "vmssProvisioningState" : stringPtrToString (val .ProvisioningState ),
219+ }
220+ infoLabels = azureResourceTags .appendPrometheusLabel (infoLabels , val .Tags )
221+ infoMetric .AddInfo (infoLabels )
222+
223+ if val .Sku != nil && val .Sku .Capacity != nil {
224+ capacityMetric .Add (prometheus.Labels {
225+ "resourceID" : * val .ID ,
226+ "subscriptionID" : * subscription .SubscriptionID ,
227+ "location" : stringPtrToString (val .Location ),
228+ "resourceGroup" : extractResourceGroupFromAzureId (* val .ID ),
229+ "vmssName" : stringPtrToString (val .Name ),
230+ }, float64 (* val .Sku .Capacity ))
231+ }
232+
233+ if list .NextWithContext (ctx ) != nil {
234+ break
235+ }
236+ }
237+
238+ callback <- func () {
239+ infoMetric .GaugeSet (m .prometheus .vmss )
240+ capacityMetric .GaugeSet (m .prometheus .vmssCapacity )
241+ }
242+ }
0 commit comments