From 59f8aa1c3160ac37a0db0d578cab68f02be75ded Mon Sep 17 00:00:00 2001 From: Michael Kroes Date: Sun, 1 Nov 2015 03:29:45 -0500 Subject: [PATCH 1/2] Add checks to the management interface to report memory usage --- management/status_checks.py | 23 +++++++++++++++++++++++ setup/management.sh | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/management/status_checks.py b/management/status_checks.py index 4b6947e0..047de4b0 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -11,6 +11,7 @@ import sys, os, os.path, re, subprocess, datetime, multiprocessing.pool import dns.reversename, dns.resolver import dateutil.parser, dateutil.tz import idna +import psutil from dns_update import get_dns_zones, build_tlsa_record, get_custom_dns_config, get_secondary_dns, get_custom_dns_record from web_update import get_web_domains, get_default_www_redirects, get_ssl_certificates, get_domain_ssl_files, get_domains_with_a_records @@ -152,6 +153,7 @@ def run_system_checks(rounded_values, env, output): check_miab_version(env, output) check_system_aliases(env, output) check_free_disk_space(rounded_values, env, output) + check_free_memory(rounded_values, env, output) def check_ssh_password(env, output): # Check that SSH login with password is disabled. The openssh-server @@ -202,6 +204,27 @@ def check_free_disk_space(rounded_values, env, output): else: output.print_error(disk_msg) +def check_free_memory(rounded_values, env, output): + # Check free memory. + percent_used = psutil.virtual_memory().percent + percent_left = 100 - percent_used + if not rounded_values: + memory_msg = "The system has allocated %s%% of the memory." % str(round(percent_used)) + if percent_left > 20: + output.print_ok(memory_msg) + elif percent_left > 15: + output.print_warning(memory_msg) + else: + output.print_error(memory_msg) + else: + memory_msg = "The system has less than %s%% memory left." % str(round(percent_left)) + if percent_left > 20: + output.print_ok("The system has more than 20% memory left") + elif percent_left > 15: + output.print_warning("The system has less than 20% memory left but more than 15%") + else: + output.print_error("The system has less than 15% memory left") + def run_network_checks(env, output): # Also see setup/network-checks.sh. diff --git a/setup/management.sh b/setup/management.sh index c4af7092..2eb652f7 100755 --- a/setup/management.sh +++ b/setup/management.sh @@ -7,7 +7,7 @@ echo "Installing Mail-in-a-Box system management daemon..." # build-essential libssl-dev libffi-dev python3-dev: Required to pip install cryptography. apt_install python3-flask links duplicity libyaml-dev python3-dnspython python3-dateutil \ build-essential libssl-dev libffi-dev python3-dev python-pip -hide_output pip3 install --upgrade rtyaml "email_validator>=1.0.0" "idna>=2.0.0" "cryptography>=1.0.2" boto +hide_output pip3 install --upgrade rtyaml "email_validator>=1.0.0" "idna>=2.0.0" "cryptography>=1.0.2" boto psutil # duplicity uses python 2 so we need to use the python 2 package of boto hide_output pip install --upgrade boto From a9cd72bbf930381503f282f42f038dfad39b7e28 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Fri, 1 Jan 2016 18:11:27 -0500 Subject: [PATCH 2/2] tighten the status text strings for free memory, add changelog entry --- CHANGELOG.md | 4 ++++ management/status_checks.py | 27 ++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31726dc8..414dc977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +Control Panel: + +* Report free memory usage. + Still In Development -------------------- diff --git a/management/status_checks.py b/management/status_checks.py index 047de4b0..151253b0 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -206,24 +206,17 @@ def check_free_disk_space(rounded_values, env, output): def check_free_memory(rounded_values, env, output): # Check free memory. - percent_used = psutil.virtual_memory().percent - percent_left = 100 - percent_used - if not rounded_values: - memory_msg = "The system has allocated %s%% of the memory." % str(round(percent_used)) - if percent_left > 20: - output.print_ok(memory_msg) - elif percent_left > 15: - output.print_warning(memory_msg) - else: - output.print_error(memory_msg) + percent_free = 100 - psutil.virtual_memory().percent + memory_msg = "System memory is %s%% free." % str(round(percent_free)) + if percent_free >= 30: + if rounded_values: memory_msg = "System free memory is at least 30%." + output.print_ok(memory_msg) + elif percent_free >= 15: + if rounded_values: memory_msg = "System free memory is below 30%." + output.print_warning(memory_msg) else: - memory_msg = "The system has less than %s%% memory left." % str(round(percent_left)) - if percent_left > 20: - output.print_ok("The system has more than 20% memory left") - elif percent_left > 15: - output.print_warning("The system has less than 20% memory left but more than 15%") - else: - output.print_error("The system has less than 15% memory left") + if rounded_values: memory_msg = "System free memory is below 15%." + output.print_error(memory_msg) def run_network_checks(env, output): # Also see setup/network-checks.sh.