From 23a8ade61524f80ae9b6cf04eb9553396693551f Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Wed, 16 Oct 2024 11:36:47 +0200 Subject: [PATCH 1/7] let's also gather quota usage --- fedcloud_vm_monitoring/site_monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index 87ee784..23a0456 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -370,7 +370,7 @@ def vo_check(self): return endpoint is not None def get_quota(self): - command = ("quota", "show") + command = ("quota", "show", "--usage") return self._run_command(command, do_raise=False) def show_quotas(self): From c0de68875e9257d5a6f2209a9c4cf563e200ab91 Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Wed, 16 Oct 2024 11:39:41 +0200 Subject: [PATCH 2/7] secgroups instead of secgroup --- fedcloud_vm_monitoring/site_monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index 23a0456..66a4752 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -383,7 +383,7 @@ def show_quotas(self): "ram", "floating-ips", "secgroup-rules", - "secgroup", + "secgroups", ] quota_info = {} for r in quota: From 099e292551d3d4d58ee12f475a246133a39b40bd Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Wed, 16 Oct 2024 12:14:17 +0200 Subject: [PATCH 3/7] work with quota usage --- fedcloud_vm_monitoring/site_monitor.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index 66a4752..bb06549 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -389,19 +389,22 @@ def show_quotas(self): for r in quota: if r["Resource"] in resources: if r["Resource"] == "ram": - quota_info[r["Resource"] + " (GB)"] = int(r["Limit"] / 1024) + quota_info["ram (GB)"] = { + "In Use": int(r["In Use"] / 1024), + "Limit": int(r["Limit"] / 1024) + } else: - quota_info[r["Resource"]] = r["Limit"] + quota_info[r["Resource"]] = {"In Use": r["In Use"], "Limit": r["Limit"]} for k, v in quota_info.items(): click.echo(f" {k:<14} = {v}") # checks on quota - if quota_info.get("ram", 1) / quota_info.get("cpu", 1) < self.min_ram_cpu_ratio: + if quota_info.get("ram (GB)").get("Limit", 1) / quota_info.get("cores").get("Limit", 1) < self.min_ram_cpu_ratio: click.secho( f"[-] WARNING: Less than {int(self.min_ram_cpu_ratio/1024)} GB RAM per available CPU", fg="yellow", ) if ( - quota_info.get("secgroup", 1) / quota_info.get("instances", 1) + quota_info.get("secgroups").get("Limit", 1) / quota_info.get("instances").get("Limit", 1) < self.min_secgroup_instance_ratio ): click.secho( @@ -409,7 +412,7 @@ def show_quotas(self): fg="yellow", ) if ( - quota_info.get("floating-ips", 1) / quota_info.get("instances", 1) + quota_info.get("floating-ips").get("Limit", 1) / quota_info.get("instances").get("Limit", 1) < self.min_ip_instance_ratio ): click.secho( From cd23c96542bdd91e5d5e38201e5f23a479b3872d Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Wed, 16 Oct 2024 12:17:31 +0200 Subject: [PATCH 4/7] bugfix min_ram_cpu_ratio check --- fedcloud_vm_monitoring/site_monitor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index bb06549..d71e433 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -24,7 +24,7 @@ class SiteMonitor: color_maps = defaultdict(lambda: "red", ACTIVE="green", BUILD="yellow") # at least 1GB per core - min_ram_cpu_ratio = 1024 + min_ram_cpu_ratio = 1 min_secgroup_instance_ratio = 3 min_ip_instance_ratio = 1 @@ -400,7 +400,7 @@ def show_quotas(self): # checks on quota if quota_info.get("ram (GB)").get("Limit", 1) / quota_info.get("cores").get("Limit", 1) < self.min_ram_cpu_ratio: click.secho( - f"[-] WARNING: Less than {int(self.min_ram_cpu_ratio/1024)} GB RAM per available CPU", + f"[-] WARNING: Less than {self.min_ram_cpu_ratio} GB RAM per available CPU", fg="yellow", ) if ( From 1292cb3db6ff1ae78e5144457e7dd95cb0f35007 Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Wed, 16 Oct 2024 14:42:57 +0200 Subject: [PATCH 5/7] improve quota output info --- fedcloud_vm_monitoring/site_monitor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index d71e433..5bbd18e 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -390,13 +390,18 @@ def show_quotas(self): if r["Resource"] in resources: if r["Resource"] == "ram": quota_info["ram (GB)"] = { - "In Use": int(r["In Use"] / 1024), - "Limit": int(r["Limit"] / 1024) - } + "In Use": int(r["In Use"] / 1024), + "Limit": int(r["Limit"] / 1024) + } else: quota_info[r["Resource"]] = {"In Use": r["In Use"], "Limit": r["Limit"]} for k, v in quota_info.items(): - click.echo(f" {k:<14} = {v}") + click.echo(" {:<14} = Limit: {:>3}, Used: {:>3} ({}%)".format( + k, + v["Limit"], + v["In Use"], + round(v["In Use"]/v["Limit"]*100) + )) # checks on quota if quota_info.get("ram (GB)").get("Limit", 1) / quota_info.get("cores").get("Limit", 1) < self.min_ram_cpu_ratio: click.secho( From 13ca9e1c9c6ef139c1138fe270597ecef1c180ca Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Thu, 17 Oct 2024 07:41:58 +0200 Subject: [PATCH 6/7] linting --- fedcloud_vm_monitoring/site_monitor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index 5bbd18e..61d290e 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -403,7 +403,10 @@ def show_quotas(self): round(v["In Use"]/v["Limit"]*100) )) # checks on quota - if quota_info.get("ram (GB)").get("Limit", 1) / quota_info.get("cores").get("Limit", 1) < self.min_ram_cpu_ratio: + if ( + quota_info.get("ram (GB)").get("Limit", 1) / quota_info.get("cores").get("Limit", 1) + < self.min_ram_cpu_ratio: + ): click.secho( f"[-] WARNING: Less than {self.min_ram_cpu_ratio} GB RAM per available CPU", fg="yellow", From 9ec4df6eeacdf2a96cb28b35a40e7435b009bfc9 Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Thu, 17 Oct 2024 07:46:30 +0200 Subject: [PATCH 7/7] linting --- fedcloud_vm_monitoring/site_monitor.py | 29 +++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index 61d290e..3d18ae3 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -391,28 +391,32 @@ def show_quotas(self): if r["Resource"] == "ram": quota_info["ram (GB)"] = { "In Use": int(r["In Use"] / 1024), - "Limit": int(r["Limit"] / 1024) + "Limit": int(r["Limit"] / 1024), } else: - quota_info[r["Resource"]] = {"In Use": r["In Use"], "Limit": r["Limit"]} + quota_info[r["Resource"]] = { + "In Use": r["In Use"], + "Limit": r["Limit"], + } for k, v in quota_info.items(): - click.echo(" {:<14} = Limit: {:>3}, Used: {:>3} ({}%)".format( - k, - v["Limit"], - v["In Use"], - round(v["In Use"]/v["Limit"]*100) - )) + click.echo( + " {:<14} = Limit: {:>3}, Used: {:>3} ({}%)".format( + k, v["Limit"], v["In Use"], round(v["In Use"] / v["Limit"] * 100) + ) + ) # checks on quota if ( - quota_info.get("ram (GB)").get("Limit", 1) / quota_info.get("cores").get("Limit", 1) - < self.min_ram_cpu_ratio: + quota_info.get("ram (GB)").get("Limit", 1) + / quota_info.get("cores").get("Limit", 1) + < self.min_ram_cpu_ratio ): click.secho( f"[-] WARNING: Less than {self.min_ram_cpu_ratio} GB RAM per available CPU", fg="yellow", ) if ( - quota_info.get("secgroups").get("Limit", 1) / quota_info.get("instances").get("Limit", 1) + quota_info.get("secgroups").get("Limit", 1) + / quota_info.get("instances").get("Limit", 1) < self.min_secgroup_instance_ratio ): click.secho( @@ -420,7 +424,8 @@ def show_quotas(self): fg="yellow", ) if ( - quota_info.get("floating-ips").get("Limit", 1) / quota_info.get("instances").get("Limit", 1) + quota_info.get("floating-ips").get("Limit", 1) + / quota_info.get("instances").get("Limit", 1) < self.min_ip_instance_ratio ): click.secho(