@@ -110,11 +110,18 @@ def get_resource_provider_info(compute_client, placement_client):
110110
111111 raw_rps = list (placement_client .resource_providers ())
112112
113+ skip_aggregate_lookup = (
114+ int (os .environ .get ("OS_CAPACITY_SKIP_AGGREGATE_LOOKUP" , "0" )) == 1
115+ )
113116 resource_providers = {}
114117 for raw_rp in raw_rps :
115118 rp = {"uuid" : raw_rp .id }
116119 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+
118125 response = placement_client .get (
119126 f"/resource_providers/{ raw_rp .id } /aggregates" ,
120127 headers = {"OpenStack-API-Version" : "placement 1.19" },
@@ -311,6 +318,11 @@ def collect(self):
311318 print (f"Collect started { collect_id } " )
312319 guages = []
313320
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+
314326 conn = openstack .connect ()
315327 openstack .enable_logging (debug = False )
316328 try :
@@ -321,19 +333,29 @@ def collect(self):
321333
322334 host_time = time .perf_counter ()
323335 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+ )
333339
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" )
337359 except Exception as e :
338360 print (f"error { e } " )
339361
@@ -345,8 +367,8 @@ def collect(self):
345367
346368if __name__ == "__main__" :
347369 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" ),
350372 }
351373 prom_client .start_http_server (** kwargs )
352374
0 commit comments