@@ -160,7 +160,7 @@ def get_host_details(compute_client, placement_client):
160
160
# capacity per host
161
161
free_by_flavor_hypervisor = prom_core .GaugeMetricFamily (
162
162
"openstack_free_capacity_hypervisor_by_flavor" ,
163
- "Free capacity if you fill the cloud full of each flavor" ,
163
+ "Free capacity for each hypervisor if you fill remaining space full of each flavor" ,
164
164
labels = ["hypervisor" , "flavor_name" , "az_aggregate" , "project_aggregate" ],
165
165
)
166
166
resource_providers , project_to_aggregate = get_resource_provider_info (
@@ -188,7 +188,7 @@ def get_host_details(compute_client, placement_client):
188
188
189
189
project_filter_aggregates = prom_core .GaugeMetricFamily (
190
190
"openstack_project_filter_aggregate" ,
191
- "Free capacity if you fill the cloud full of each flavor " ,
191
+ "Mapping of project_ids to aggregates in the host free capacity info. " ,
192
192
labels = ["project_id" , "aggregate" ],
193
193
)
194
194
for project , names in project_to_aggregate .items ():
@@ -204,7 +204,7 @@ def get_host_details(compute_client, placement_client):
204
204
]
205
205
206
206
207
- def print_project_usage (indentity_client , placement_client , compute_client ):
207
+ def get_project_usage (indentity_client , placement_client , compute_client ):
208
208
projects = {proj .id : dict (name = proj .name ) for proj in indentity_client .projects ()}
209
209
for project_id in projects .keys ():
210
210
# TODO(johngarbutt) On Xena we should do consumer_type=INSTANCE using 1.38!
@@ -225,27 +225,32 @@ def print_project_usage(indentity_client, placement_client, compute_client):
225
225
projects [project_id ]["quotas" ] = dict (
226
226
CPUS = quotas .get ("cores" ), MEMORY_MB = quotas .get ("ram" )
227
227
)
228
-
229
228
# print(json.dumps(projects, indent=2))
229
+
230
+ project_usage_guage = prom_core .GaugeMetricFamily (
231
+ "openstack_project_usage" ,
232
+ "Current placement allocations per project." ,
233
+ labels = ["project_id" , "project_name" , "placement_resource" ],
234
+ )
235
+ project_quota_guage = prom_core .GaugeMetricFamily (
236
+ "openstack_project_quota" ,
237
+ "Current quota set to limit max resource allocations per project." ,
238
+ labels = ["project_id" , "project_name" , "quota_resource" ],
239
+ )
230
240
for project_id , data in projects .items ():
231
241
name = data ["name" ]
232
242
project_usages = data ["usages" ]
233
243
for resource , amount in project_usages .items ():
234
- print (
235
- f'openstack_project_usage{{project_id="{ project_id } ",'
236
- f'project_name="{ name } ",resource="{ resource } "}} { amount } '
237
- )
244
+ project_usage_guage .add_metric ([project_id , name , resource ], amount )
238
245
239
246
if not project_usages :
240
247
# skip projects with zero usage?
241
248
print (f"# WARNING no usage for project: { name } { project_id } " )
242
249
continue
243
250
project_quotas = data ["quotas" ]
244
251
for resource , amount in project_quotas .items ():
245
- print (
246
- f'openstack_project_quota{{project_id="{ project_id } ",'
247
- f'project_name="{ name } ",resource="{ resource } "}} { amount } '
248
- )
252
+ project_quota_guage .add_metric ([project_id , name , resource ], amount )
253
+ return [project_usage_guage , project_quota_guage ]
249
254
250
255
251
256
def print_host_usage (resource_providers , placement_client ):
@@ -308,7 +313,7 @@ def collect(self):
308
313
)
309
314
guages += host_guages
310
315
311
- print_project_usage (conn .identity , conn .placement , conn .compute )
316
+ guages += get_project_usage (conn .identity , conn .placement , conn .compute )
312
317
print_host_usage (resource_providers , conn .placement )
313
318
except Exception as e :
314
319
print (f"error { e } " )
0 commit comments