Skip to content

Commit

Permalink
Merge pull request #12 from stackhpc/skip_some_bits
Browse files Browse the repository at this point in the history
Add ability to skip some bits
  • Loading branch information
JohnGarbutt authored Mar 30, 2023
2 parents 794946a + e4dd350 commit b2e977c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 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
52 changes: 37 additions & 15 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,6 +318,11 @@ def collect(self):
print(f"Collect started {collect_id}")
guages = []

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)
try:
Expand All @@ -321,19 +333,29 @@ 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")

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")

guages += get_host_usage(resource_providers, conn.placement)
print(
f"1 of 3: host flavor capacity complete for {collect_id} it took {host_duration} seconds"
)

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")
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"
)
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"
)
else:
print("3 of 3: skipping host usage")
except Exception as e:
print(f"error {e}")

Expand All @@ -345,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 b2e977c

Please sign in to comment.