Skip to content

Commit d2f22de

Browse files
committed
Add project guages
1 parent f97eb87 commit d2f22de

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

os_capacity/prometheus.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def get_host_details(compute_client, placement_client):
160160
# capacity per host
161161
free_by_flavor_hypervisor = prom_core.GaugeMetricFamily(
162162
"openstack_free_capacity_hypervisor_by_flavor",
163-
"Free capacity if you fill the cloud full of each flavor",
163+
"Free capacity for each hypervisor if you fill remaining space full of each flavor",
164164
labels=["hypervisor", "flavor_name", "az_aggregate", "project_aggregate"],
165165
)
166166
resource_providers, project_to_aggregate = get_resource_provider_info(
@@ -188,7 +188,7 @@ def get_host_details(compute_client, placement_client):
188188

189189
project_filter_aggregates = prom_core.GaugeMetricFamily(
190190
"openstack_project_filter_aggregate",
191-
"Free capacity if you fill the cloud full of each flavor",
191+
"Mapping of project_ids to aggregates in the host free capacity info.",
192192
labels=["project_id", "aggregate"],
193193
)
194194
for project, names in project_to_aggregate.items():
@@ -204,7 +204,7 @@ def get_host_details(compute_client, placement_client):
204204
]
205205

206206

207-
def print_project_usage(indentity_client, placement_client, compute_client):
207+
def get_project_usage(indentity_client, placement_client, compute_client):
208208
projects = {proj.id: dict(name=proj.name) for proj in indentity_client.projects()}
209209
for project_id in projects.keys():
210210
# TODO(johngarbutt) On Xena we should do consumer_type=INSTANCE using 1.38!
@@ -225,27 +225,32 @@ def print_project_usage(indentity_client, placement_client, compute_client):
225225
projects[project_id]["quotas"] = dict(
226226
CPUS=quotas.get("cores"), MEMORY_MB=quotas.get("ram")
227227
)
228-
229228
# print(json.dumps(projects, indent=2))
229+
230+
project_usage_guage = prom_core.GaugeMetricFamily(
231+
"openstack_project_usage",
232+
"Current placement allocations per project.",
233+
labels=["project_id", "project_name", "placement_resource"],
234+
)
235+
project_quota_guage = prom_core.GaugeMetricFamily(
236+
"openstack_project_quota",
237+
"Current quota set to limit max resource allocations per project.",
238+
labels=["project_id", "project_name", "quota_resource"],
239+
)
230240
for project_id, data in projects.items():
231241
name = data["name"]
232242
project_usages = data["usages"]
233243
for resource, amount in project_usages.items():
234-
print(
235-
f'openstack_project_usage{{project_id="{project_id}",'
236-
f'project_name="{name}",resource="{resource}"}} {amount}'
237-
)
244+
project_usage_guage.add_metric([project_id, name, resource], amount)
238245

239246
if not project_usages:
240247
# skip projects with zero usage?
241248
print(f"# WARNING no usage for project: {name} {project_id}")
242249
continue
243250
project_quotas = data["quotas"]
244251
for resource, amount in project_quotas.items():
245-
print(
246-
f'openstack_project_quota{{project_id="{project_id}",'
247-
f'project_name="{name}",resource="{resource}"}} {amount}'
248-
)
252+
project_quota_guage.add_metric([project_id, name, resource], amount)
253+
return [project_usage_guage, project_quota_guage]
249254

250255

251256
def print_host_usage(resource_providers, placement_client):
@@ -308,7 +313,7 @@ def collect(self):
308313
)
309314
guages += host_guages
310315

311-
print_project_usage(conn.identity, conn.placement, conn.compute)
316+
guages += get_project_usage(conn.identity, conn.placement, conn.compute)
312317
print_host_usage(resource_providers, conn.placement)
313318
except Exception as e:
314319
print(f"error {e}")

0 commit comments

Comments
 (0)