@@ -110,11 +110,18 @@ def get_resource_provider_info(compute_client, placement_client):
110
110
111
111
raw_rps = list (placement_client .resource_providers ())
112
112
113
+ skip_aggregate_lookup = (
114
+ int (os .environ .get ("OS_CAPACITY_SKIP_AGGREGATE_LOOKUP" , "0" )) == 1
115
+ )
113
116
resource_providers = {}
114
117
for raw_rp in raw_rps :
115
118
rp = {"uuid" : raw_rp .id }
116
119
resource_providers [raw_rp .name ] = rp
117
- # TODO - get aggregates
120
+
121
+ if skip_aggregate_lookup :
122
+ # skip checking every resource provider for their aggregates
123
+ continue
124
+
118
125
response = placement_client .get (
119
126
f"/resource_providers/{ raw_rp .id } /aggregates" ,
120
127
headers = {"OpenStack-API-Version" : "placement 1.19" },
@@ -311,6 +318,11 @@ def collect(self):
311
318
print (f"Collect started { collect_id } " )
312
319
guages = []
313
320
321
+ skip_project_usage = (
322
+ int (os .environ .get ("OS_CAPACITY_SKIP_PROJECT_USAGE" , "0" )) == 1
323
+ )
324
+ skip_host_usage = int (os .environ .get ("OS_CAPACITY_SKIP_HOST_USAGE" , "0" )) == 1
325
+
314
326
conn = openstack .connect ()
315
327
openstack .enable_logging (debug = False )
316
328
try :
@@ -321,19 +333,29 @@ def collect(self):
321
333
322
334
host_time = time .perf_counter ()
323
335
host_duration = host_time - start_time
324
- print (f"1 of 3 host flavor capacity complete for { collect_id } it took { host_duration } seconds" )
325
-
326
- guages += get_project_usage (conn .identity , conn .placement , conn .compute )
327
-
328
- project_time = time .perf_counter ()
329
- project_duration = project_time - host_time
330
- print (f"2 of 3 project usage complete for { collect_id } it took { project_duration } seconds" )
331
-
332
- guages += get_host_usage (resource_providers , conn .placement )
336
+ print (
337
+ f"1 of 3: host flavor capacity complete for { collect_id } it took { host_duration } seconds"
338
+ )
333
339
334
- host_usage_time = time .perf_counter ()
335
- host_usage_duration = host_usage_time - project_time
336
- print (f"3 of 3 host usage complete for { collect_id } it took { host_usage_duration } seconds" )
340
+ if not skip_project_usage :
341
+ guages += get_project_usage (conn .identity , conn .placement , conn .compute )
342
+ project_time = time .perf_counter ()
343
+ project_duration = project_time - host_time
344
+ print (
345
+ f"2 of 3: project usage complete for { collect_id } it took { project_duration } seconds"
346
+ )
347
+ else :
348
+ print ("2 of 3: skipping project usage" )
349
+
350
+ if not skip_project_usage :
351
+ guages += get_host_usage (resource_providers , conn .placement )
352
+ host_usage_time = time .perf_counter ()
353
+ host_usage_duration = host_usage_time - project_time
354
+ print (
355
+ f"3 of 3: host usage complete for { collect_id } it took { host_usage_duration } seconds"
356
+ )
357
+ else :
358
+ print ("3 of 3: skipping host usage" )
337
359
except Exception as e :
338
360
print (f"error { e } " )
339
361
@@ -345,8 +367,8 @@ def collect(self):
345
367
346
368
if __name__ == "__main__" :
347
369
kwargs = {
348
- "port" : int (os .environ .get (' OS_CAPACITY_EXPORTER_PORT' , 9000 )),
349
- "addr" : os .environ .get (' OS_CAPACITY_EXPORTER_LISTEN_ADDRESS' , ' 0.0.0.0' ),
370
+ "port" : int (os .environ .get (" OS_CAPACITY_EXPORTER_PORT" , 9000 )),
371
+ "addr" : os .environ .get (" OS_CAPACITY_EXPORTER_LISTEN_ADDRESS" , " 0.0.0.0" ),
350
372
}
351
373
prom_client .start_http_server (** kwargs )
352
374
0 commit comments