diff --git a/CHANGELOG.md b/CHANGELOG.md index 497b7a1d5c3fa3eea9c84f06d6785e34117c28d0..6287232acd7a770493d891adcea4f068bb82422c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.4.0] - 2023-08-28 +### Added +- New metrics custom_openstack_server_info and custom_openstack_flavor_info + ## [1.3.0] - 2023-04-11 ### Fix - Adding HTTP + HTTPS port checking diff --git a/custom-openstack-exporter.py b/custom-openstack-exporter.py index 3fb3ed41b111df7f7af4df4b06a99441e462d747..cb0e1fe9117bb0f65fa0d98dc292a4091d8c1230 100755 --- a/custom-openstack-exporter.py +++ b/custom-openstack-exporter.py @@ -78,6 +78,12 @@ class AppMetrics: self.openstack_project_info = Gauge("custom_openstack_project_info", "Custom info for a project", ["project_id", "project_name", "domain_id", "project_tag"]) + self.openstack_server_info = Gauge("custom_openstack_server_info", + "Custom info for a server", + ["server_id", "server_name", "image_id", "flavor_name"]) + self.openstack_flavor_info = Gauge("custom_openstack_flavor_info", + "Openstack flavor parameters", + ["flavor_id", "flavor_name", "ram", "disk", "vcpus", "public", "ephemeral", "disabled"]) self.openstack_loadbalancer_status = Gauge("custom_openstack_loadbalancer_accessibility_status", "LoadBalancer accessibility status", ["id", "status"]) self.openstack_ip_status = Gauge("custom_openstack_ip_accessibility_status", @@ -89,6 +95,8 @@ class AppMetrics: while True: self.fetch_fip_quota() self.fetch_project_info() + self.fetch_server_info() + self.fetch_flavor_info() self.fetch_ip_status() self.fetch_loadbalancer_status() time.sleep(self.polling_interval_seconds) @@ -131,6 +139,44 @@ class AppMetrics: project_tag="" ).set(project['is_enabled']) + def fetch_server_info(self): + """ + Get metrics from application and refresh Prometheus metrics with + new values. + """ + + # remove all statuses + self.openstack_server_info.clear() + + for server in self.os_connection.compute.servers(True,True): + self.openstack_server_info.labels( + server_id=server['id'], + server_name=server['name'], + image_id=server['image']['id'], + flavor_name=server['flavor']['original_name'] + ).set(1) + + def fetch_flavor_info(self): + """ + Get metrics from application and refresh Prometheus metrics with + new values. + """ + + # remove all statuses + self.openstack_flavor_info.clear() + + for flavor in self.os_connection.compute.flavors(): + self.openstack_flavor_info.labels( + flavor_id=flavor['id'], + flavor_name=flavor['name'], + ram=flavor['ram'], + disk=flavor['disk'], + vcpus=flavor['vcpus'], + public=flavor['os-flavor-access:is_public'], + ephemeral=flavor['OS-FLV-EXT-DATA:ephemeral'], + disabled=flavor['OS-FLV-DISABLED:disabled'] + ).set(1) + # support function for ip status evaluation @staticmethod def get_ip_accessibility_status_ping(ip_address):