diff --git a/src/pvecontrol/sanitycheck.py b/src/pvecontrol/sanitycheck.py index 9bd4adc..da76a78 100644 --- a/src/pvecontrol/sanitycheck.py +++ b/src/pvecontrol/sanitycheck.py @@ -62,12 +62,14 @@ def display(self, padding_max_size): class SanityCheck(): check_methods = ( + "_validate_nodes_capacity", "_validate_ha_groups", "_validate_ha_vms", ) check_display_order = [ CheckType.HA, + CheckType.Node, ] def __init__(self, proxmox: PVECluster): @@ -97,6 +99,32 @@ def display(self): print(f"{dash_size*'-'} {check.type.value} {dash_size*'-'}\n") check.display(size) + def _check_cpu_overcommit(self, maxcpu, cpufactor, allocated_cpu): + return (maxcpu * cpufactor) <= allocated_cpu + + def _check_mem_overcommit(self, max_mem, min_mem, allocated_mem): + return (allocated_mem + min_mem) >= max_mem + + # Check nodes capacity + def _validate_nodes_capacity(self): + node_config = self._proxmox.config['node'] + check = Check(CheckType.Node, "Check Node capacity") + for node in self._proxmox.nodes: + if self._check_cpu_overcommit(node.maxcpu, node_config['cpufactor'], node.allocatedcpu): + msg = "Node %s is in cpu overcommit status: %s allocated but %s available"%(node.node, node.allocatedcpu, node.maxcpu) + check.add_messages(CheckMessage(CheckCode.CRIT, msg)) + else: + msg = f"Node '{node.node}' isn't in cpu overcommit" + check.add_messages(CheckMessage(CheckCode.OK, msg)) + + if self._check_mem_overcommit(node.allocatedmem, node_config['memoryminimum'], node.maxmem): + msg = f"Node '{node.node}' is in mem overcommit status: {node.allocatedmem} allocated but {node.maxmem} available" + check.add_messages(CheckMessage(CheckCode.CRIT, msg)) + else: + msg = f"Node '{node.node}' isn't in cpu overcommit" + check.add_messages(CheckMessage(CheckCode.OK, msg)) + return check + # Check HA groups def _validate_ha_groups(self): check = Check(CheckType.HA, "Check HA groups")