Skip to content

Commit

Permalink
Handle multiple aggregates properly (#135)
Browse files Browse the repository at this point in the history
Currently, if there are multiple aggregates present only the last one is displayed. 
So the current handling is broken. This change lists them all so that it be grouped 
by hypervisors and/or individual aggregate type(s). Fixes #38.

Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored Aug 21, 2024
1 parent ef188e2 commit cd4ffff
Showing 1 changed file with 58 additions and 24 deletions.
82 changes: 58 additions & 24 deletions prometheus-openstack-exporter
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ class Nova:
if s["binary"] == "nova-compute":
self.services_map[s["host"]] = s["status"]
for agg in self.prodstack["aggregates"]:
self.aggregate_map.update({i: agg["name"] for i in agg["hosts"]})
self.aggregate_map.update({host + "_" + agg["name"]: agg["name"]
for host in agg["hosts"]})

def _get_schedulable_instances(self, host):
free_vcpus = (
Expand Down Expand Up @@ -616,29 +617,62 @@ class Nova:
elif not isinstance(cpu_info, dict):
cpu_info = json.loads(cpu_info)
arch = cpu_info["arch"]
label_values = [
config["cloud"],
host,
self.aggregate_map.get(host, "unknown"),
self.services_map[host],
arch,
]
# Disabled hypervisors return None below, convert to 0
vms.labels(*label_values).set(squashnone(h["running_vms"]))
vcpus_total.labels(*label_values).set(squashnone(h["vcpus"]))
vcpus_used.labels(*label_values).set(squashnone(h["vcpus_used"]))
mem_total.labels(*label_values).set(squashnone(h["memory_mb"]))
mem_used.labels(*label_values).set(squashnone(h["memory_mb_used"]))
disk_total.labels(*label_values).set(squashnone(h["local_gb"]))
disk_used.labels(*label_values).set(squashnone(h["local_gb_used"]))

if config.get("schedulable_instance_size", False):
schedulable_instances.labels(*label_values).set(
self._get_schedulable_instances(h)
)
schedulable_instances_capacity.labels(*label_values).set(
self._get_schedulable_instances_capacity(h)
)

at_least_one_aggregate = False
for agg in self.prodstack["aggregates"]:
agg_key = host + "_" + agg["name"]
if self.aggregate_map.get(agg_key) is None:
continue
at_least_one_aggregate = True
label_values = [
config["cloud"],
host,
self.aggregate_map[agg_key],
self.services_map[host],
arch,
]
# Disabled hypervisors return None below, convert to 0
vms.labels(*label_values).set(squashnone(h["running_vms"]))
vcpus_total.labels(*label_values).set(squashnone(h["vcpus"]))
vcpus_used.labels(*label_values).set(squashnone(h["vcpus_used"]))
mem_total.labels(*label_values).set(squashnone(h["memory_mb"]))
mem_used.labels(*label_values).set(squashnone(h["memory_mb_used"]))
disk_total.labels(*label_values).set(squashnone(h["local_gb"]))
disk_used.labels(*label_values).set(squashnone(h["local_gb_used"]))

if config.get("schedulable_instance_size", False):
schedulable_instances.labels(*label_values).set(
self._get_schedulable_instances(h)
)
schedulable_instances_capacity.labels(*label_values).set(
self._get_schedulable_instances_capacity(h)
)

# host isn't part of any aggregate
if not at_least_one_aggregate:
label_values = [
config["cloud"],
host,
"unknown",
self.services_map[host],
arch,
]
# Disabled hypervisors return None below, convert to 0
vms.labels(*label_values).set(squashnone(h["running_vms"]))
vcpus_total.labels(*label_values).set(squashnone(h["vcpus"]))
vcpus_used.labels(*label_values).set(squashnone(h["vcpus_used"]))
mem_total.labels(*label_values).set(squashnone(h["memory_mb"]))
mem_used.labels(*label_values).set(squashnone(h["memory_mb_used"]))
disk_total.labels(*label_values).set(squashnone(h["local_gb"]))
disk_used.labels(*label_values).set(squashnone(h["local_gb_used"]))

if config.get("schedulable_instance_size", False):
schedulable_instances.labels(*label_values).set(
self._get_schedulable_instances(h)
)
schedulable_instances_capacity.labels(*label_values).set(
self._get_schedulable_instances_capacity(h)
)

def gen_instance_stats(self):
"""Collect Nova instances statistics."""
Expand Down

0 comments on commit cd4ffff

Please sign in to comment.