mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Rework diagnosis of system resources
This commit is contained in:
parent
a03ee5b912
commit
4787f0ce04
2 changed files with 65 additions and 33 deletions
|
@ -12,22 +12,24 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
|
||||
def run(self):
|
||||
|
||||
MB = 1024**2
|
||||
GB = 1024**2
|
||||
|
||||
#
|
||||
# RAM
|
||||
#
|
||||
|
||||
ram = psutil.virtual_memory()
|
||||
ram_total_abs_MB = ram.total / (1024**2)
|
||||
ram_available_abs_MB = ram.available / (1024**2)
|
||||
ram_available_percent = round(100 * ram.available / ram.total)
|
||||
ram_available_percent = 100 * ram.available / ram.total
|
||||
item = dict(meta={"test": "ram"},
|
||||
data={"total_abs_MB": ram_total_abs_MB,
|
||||
"available_abs_MB": ram_available_abs_MB,
|
||||
"available_percent": ram_available_percent})
|
||||
if ram_available_abs_MB < 100 or ram_available_percent < 5:
|
||||
data={"total": human_size(ram.total),
|
||||
"available": human_size(ram.available),
|
||||
"available_percent": round_(ram_available_percent)})
|
||||
|
||||
if ram.available < 100 * MB or ram_available_percent < 5:
|
||||
item["status"] = "ERROR"
|
||||
item["summary"] = "diagnosis_ram_verylow"
|
||||
elif ram_available_abs_MB < 200 or ram_available_percent < 10:
|
||||
elif ram.available < 200 * MB or ram_available_percent < 10:
|
||||
item["status"] = "WARNING"
|
||||
item["summary"] = "diagnosis_ram_low"
|
||||
else:
|
||||
|
@ -40,13 +42,12 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
#
|
||||
|
||||
swap = psutil.swap_memory()
|
||||
swap_total_abs_MB = swap.total / (1024*1024)
|
||||
item = dict(meta={"test": "swap"},
|
||||
data={"total_MB": swap_total_abs_MB})
|
||||
if swap_total_abs_MB <= 0:
|
||||
data={"total": human_size(swap.total)})
|
||||
if swap.total <= 1 * MB:
|
||||
item["status"] = "ERROR"
|
||||
item["summary"] = "diagnosis_swap_none"
|
||||
elif swap_total_abs_MB <= 256:
|
||||
elif swap.total <= 256 * MB:
|
||||
item["status"] = "WARNING"
|
||||
item["summary"] = "diagnosis_swap_notsomuch"
|
||||
else:
|
||||
|
@ -67,23 +68,54 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
mountpoint = disk_partition.mountpoint
|
||||
|
||||
usage = psutil.disk_usage(mountpoint)
|
||||
free_abs_GB = usage.free / (1024 ** 3)
|
||||
free_percent = 100 - usage.percent
|
||||
free_percent = round_(100 - usage.percent)
|
||||
|
||||
item = dict(meta={"test": "diskusage", "mountpoint": mountpoint},
|
||||
data={"device": device, "free_abs_GB": free_abs_GB, "free_percent": free_percent})
|
||||
if free_abs_GB < 1 or free_percent < 5:
|
||||
data={"device": device, "total": human_size(usage.total), "free": human_size(usage.free), "free_percent": free_percent})
|
||||
|
||||
# Special checks for /boot partition because they sometimes are
|
||||
# pretty small and that's kind of okay... (for example on RPi)
|
||||
if mountpoint.startswith("/boot"):
|
||||
if usage.free < 10 * MB or free_percent < 10:
|
||||
item["status"] = "ERROR"
|
||||
item["summary"] = "diagnosis_diskusage_verylow"
|
||||
elif free_abs_GB < 2 or free_percent < 10:
|
||||
elif usage.free < 20 * MB or free_percent < 20:
|
||||
item["status"] = "WARNING"
|
||||
item["summary"] = "diagnosis_diskusage_low"
|
||||
else:
|
||||
item["status"] = "SUCCESS"
|
||||
item["summary"] = "diagnosis_diskusage_ok"
|
||||
else:
|
||||
if usage.free < 1 * GB or free_percent < 5:
|
||||
item["status"] = "ERROR"
|
||||
item["summary"] = "diagnosis_diskusage_verylow"
|
||||
elif usage.free < 2 * GB or free_percent < 10:
|
||||
item["status"] = "WARNING"
|
||||
item["summary"] = "diagnosis_diskusage_low"
|
||||
else:
|
||||
item["status"] = "SUCCESS"
|
||||
item["summary"] = "diagnosis_diskusage_ok"
|
||||
|
||||
|
||||
yield item
|
||||
|
||||
|
||||
def human_size(bytes_):
|
||||
# Adapted from https://stackoverflow.com/a/1094933
|
||||
for unit in ['','ki','Mi','Gi','Ti','Pi','Ei','Zi']:
|
||||
if abs(bytes_) < 1024.0:
|
||||
return "%s %sB" % (round_(bytes_), unit)
|
||||
bytes_ /= 1024.0
|
||||
return "%s %sB" % (round_(bytes_), 'Yi')
|
||||
|
||||
|
||||
def round_(n):
|
||||
# round_(22.124) -> 22
|
||||
# round_(9.45) -> 9.4
|
||||
n = round(n, 1)
|
||||
if n > 10:
|
||||
n = int(round(n))
|
||||
return n
|
||||
|
||||
def main(args, env, loggers):
|
||||
return SystemResourcesDiagnoser(args, env, loggers).diagnose()
|
||||
|
|
|
@ -175,21 +175,21 @@
|
|||
"diagnosis_services_running": "Service {service} is running!",
|
||||
"diagnosis_services_conf_broken": "Configuration is broken for service {service}!",
|
||||
"diagnosis_services_bad_status": "Service {service} is {status} :(",
|
||||
"diagnosis_services_bad_status_tip": "You can try to restart the service, and if it doesn't work, have a look at the service logs using <cmd>yunohost service log {service}</cmd> or through the <a href='#/services'>'Services'</a> section of the webadmin.",
|
||||
"diagnosis_diskusage_verylow": "Storage {mountpoint} (on device {device}) has only {free_abs_GB} GB ({free_percent}%) space remaining. You should really consider cleaning up some space.",
|
||||
"diagnosis_diskusage_low": "Storage {mountpoint} (on device {device}) has only {free_abs_GB} GB ({free_percent}%) space remaining. Be careful.",
|
||||
"diagnosis_diskusage_ok": "Storage {mountpoint} (on device {device}) still has {free_abs_GB} GB ({free_percent}%) space left!",
|
||||
"diagnosis_ram_verylow": "The system has only {available_abs_MB} MB ({available_percent}%) RAM left! (out of {total_abs_MB} MB)",
|
||||
"diagnosis_ram_low": "The system has {available_abs_MB} MB ({available_percent}%) RAM left out of {total_abs_MB} MB. Be careful.",
|
||||
"diagnosis_ram_ok": "The system still has {available_abs_MB} MB ({available_percent}%) RAM left out of {total_abs_MB} MB.",
|
||||
"diagnosis_services_bad_status_tip": "You can try to <a href='#/services/{service}'>restart the service</a>, and if it doesn't work, have a look at <a href='#/services/{service}'>the service logs in the webadmin</a> (from the command line, you can do this with <cmd>yunohost service restart {service}</cmd> and <cmd>yunohost service log {service}</cmd>).",
|
||||
"diagnosis_diskusage_verylow": "Storage <code>{mountpoint}</code> (on device <code>{device}</code>) has only {free} ({free_percent}%) space remaining (out of {total}). You should really consider cleaning up some space!",
|
||||
"diagnosis_diskusage_low": "Storage <code>{mountpoint}</code> (on device <code>{device}</code>) has only {free} ({free_percent}%) space remaining (out of {total}). Be careful.",
|
||||
"diagnosis_diskusage_ok": "Storage <code>{mountpoint}</code> (on device <code>{device}</code>) still has {free} ({free_percent}%) space left (out of {total})!",
|
||||
"diagnosis_ram_verylow": "The system has only {available} ({available_percent}%) RAM available! (out of {total})",
|
||||
"diagnosis_ram_low": "The system has {available} ({available_percent}%) RAM available (out of {total}). Be careful.",
|
||||
"diagnosis_ram_ok": "The system still has {available} ({available_percent}%) RAM available out of {total}.",
|
||||
"diagnosis_swap_none": "The system has no swap at all. You should consider adding at least 256 MB of swap to avoid situations where the system runs out of memory.",
|
||||
"diagnosis_swap_notsomuch": "The system has only {total_MB} MB swap. You should consider having at least 256 MB to avoid situations where the system runs out of memory.",
|
||||
"diagnosis_swap_ok": "The system has {total_MB} MB of swap!",
|
||||
"diagnosis_swap_notsomuch": "The system has only {total} swap. You should consider having at least 256 MB to avoid situations where the system runs out of memory.",
|
||||
"diagnosis_swap_ok": "The system has {total} of swap!",
|
||||
"diagnosis_mail_ougoing_port_25_ok": "Outgoing port 25 is not blocked and email can be sent to other servers.",
|
||||
"diagnosis_mail_ougoing_port_25_blocked": "Outgoing port 25 appears to be blocked. You should try to unblock it in your internet service provider (or hosting provider) configuration panel. Meanwhile, the server won't be able to send emails to other servers.",
|
||||
"diagnosis_regenconf_allgood": "All configurations files are in line with the recommended configuration!",
|
||||
"diagnosis_regenconf_manually_modified": "Configuration file <code>{file}</code> appears to have been manually modified.",
|
||||
"diagnosis_regenconf_manually_modified_details": "This is probably OK if you know what you're doing! Though YunoHost will stop updating this file automatically, beware that YunoHost upgrades may contain important recommended changes. You can inspect the difference with <cmd>yunohost tools regen-conf {category} --dry-run --with-diff</cmd> and force the reset to the recommended configuration with <cmd>yunohost tools regen-conf {category} --force</cmd>",
|
||||
"diagnosis_regenconf_manually_modified_details": "This is probably OK if you know what you're doing! YunoHost will stop updating this file automatically... But beware that YunoHost upgrades could contain important recommended changes. If you want to, you can inspect the differences with <cmd>yunohost tools regen-conf {category} --dry-run --with-diff</cmd> and force the reset to the recommended configuration with <cmd>yunohost tools regen-conf {category} --force</cmd>",
|
||||
"diagnosis_security_all_good": "No critical security vulnerability was found.",
|
||||
"diagnosis_security_vulnerable_to_meltdown": "You appear vulnerable to the Meltdown criticial security vulnerability",
|
||||
"diagnosis_security_vulnerable_to_meltdown_details": "To fix this, you should upgrade your system and reboot to load the new linux kernel (or contact your server provider if this doesn't work). See https://meltdownattack.com/ for more infos.",
|
||||
|
|
Loading…
Add table
Reference in a new issue