Skip to content

Commit

Permalink
Add AZ skip
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGarbutt committed Mar 29, 2023
1 parent df815e5 commit e4dd350
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ Or just run via docker or similar:::
-p 9000:9000 ghcr.io/stackhpc/os-capacity:e08ecb8
curl localhost:9000


We aslo have the following optional environment variables:

* OS_CAPACITY_EXPORTER_PORT = 9000
* OS_CAPACITY_EXPORTER_LISTEN_ADDRESS = "0.0.0.0"
* OS_CAPACITY_SKIP_AGGREGATE_LOOKUP = 0
* OS_CAPACITY_SKIP_PROJECT_USAGE = 0
* OS_CAPACITY_SKIP_HOST_USAGE = 0

Here is some example output from the exporter:::

# HELP openstack_free_capacity_by_flavor_total Free capacity if you fill the cloud full of each flavor
Expand Down
31 changes: 23 additions & 8 deletions os_capacity/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ def get_resource_provider_info(compute_client, placement_client):

raw_rps = list(placement_client.resource_providers())

skip_aggregate_lookup = (
int(os.environ.get("OS_CAPACITY_SKIP_AGGREGATE_LOOKUP", "0")) == 1
)
resource_providers = {}
for raw_rp in raw_rps:
rp = {"uuid": raw_rp.id}
resource_providers[raw_rp.name] = rp
# TODO - get aggregates

if skip_aggregate_lookup:
# skip checking every resource provider for their aggregates
continue

response = placement_client.get(
f"/resource_providers/{raw_rp.id}/aggregates",
headers={"OpenStack-API-Version": "placement 1.19"},
Expand Down Expand Up @@ -311,8 +318,10 @@ def collect(self):
print(f"Collect started {collect_id}")
guages = []

skip_project_usage = int(os.environ.get('OS_CAPACITY_SKIP_PROJECT_USAGE', "0"))
skip_host_usage = int(os.environ.get('OS_CAPACITY_SKIP_HOST_USAGE', "0"))
skip_project_usage = (
int(os.environ.get("OS_CAPACITY_SKIP_PROJECT_USAGE", "0")) == 1
)
skip_host_usage = int(os.environ.get("OS_CAPACITY_SKIP_HOST_USAGE", "0")) == 1

conn = openstack.connect()
openstack.enable_logging(debug=False)
Expand All @@ -324,21 +333,27 @@ def collect(self):

host_time = time.perf_counter()
host_duration = host_time - start_time
print(f"1 of 3: host flavor capacity complete for {collect_id} it took {host_duration} seconds")
print(
f"1 of 3: host flavor capacity complete for {collect_id} it took {host_duration} seconds"
)

if not skip_project_usage:
guages += get_project_usage(conn.identity, conn.placement, conn.compute)
project_time = time.perf_counter()
project_duration = project_time - host_time
print(f"2 of 3: project usage complete for {collect_id} it took {project_duration} seconds")
print(
f"2 of 3: project usage complete for {collect_id} it took {project_duration} seconds"
)
else:
print("2 of 3: skipping project usage")

if not skip_project_usage:
guages += get_host_usage(resource_providers, conn.placement)
host_usage_time = time.perf_counter()
host_usage_duration = host_usage_time - project_time
print(f"3 of 3: host usage complete for {collect_id} it took {host_usage_duration} seconds")
print(
f"3 of 3: host usage complete for {collect_id} it took {host_usage_duration} seconds"
)
else:
print("3 of 3: skipping host usage")
except Exception as e:
Expand All @@ -352,8 +367,8 @@ def collect(self):

if __name__ == "__main__":
kwargs = {
"port": int(os.environ.get('OS_CAPACITY_EXPORTER_PORT', 9000)),
"addr": os.environ.get('OS_CAPACITY_EXPORTER_LISTEN_ADDRESS', '0.0.0.0'),
"port": int(os.environ.get("OS_CAPACITY_EXPORTER_PORT", 9000)),
"addr": os.environ.get("OS_CAPACITY_EXPORTER_LISTEN_ADDRESS", "0.0.0.0"),
}
prom_client.start_http_server(**kwargs)

Expand Down

0 comments on commit e4dd350

Please sign in to comment.