Skip to content

Commit b2e977c

Browse files
authored
Merge pull request #12 from stackhpc/skip_some_bits
Add ability to skip some bits
2 parents 794946a + e4dd350 commit b2e977c

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ Or just run via docker or similar:::
4545
-p 9000:9000 ghcr.io/stackhpc/os-capacity:e08ecb8
4646
curl localhost:9000
4747

48+
49+
We aslo have the following optional environment variables:
50+
51+
* OS_CAPACITY_EXPORTER_PORT = 9000
52+
* OS_CAPACITY_EXPORTER_LISTEN_ADDRESS = "0.0.0.0"
53+
* OS_CAPACITY_SKIP_AGGREGATE_LOOKUP = 0
54+
* OS_CAPACITY_SKIP_PROJECT_USAGE = 0
55+
* OS_CAPACITY_SKIP_HOST_USAGE = 0
56+
4857
Here is some example output from the exporter:::
4958

5059
# HELP openstack_free_capacity_by_flavor_total Free capacity if you fill the cloud full of each flavor

os_capacity/prometheus.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

346368
if __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

Comments
 (0)