diff --git a/data/hooks/diagnosis/50-diskusage.py b/data/hooks/diagnosis/50-diskusage.py deleted file mode 100644 index 74b8eb4b9..000000000 --- a/data/hooks/diagnosis/50-diskusage.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python -import os -import psutil - -from yunohost.diagnosis import Diagnoser - -class DiskUsageDiagnoser(Diagnoser): - - id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] - cache_duration = 3600 * 24 - dependencies = [] - - def run(self): - - disk_partitions = psutil.disk_partitions() - - for disk_partition in disk_partitions: - device = disk_partition.device - mountpoint = disk_partition.mountpoint - - usage = psutil.disk_usage(mountpoint) - free_Go = usage.free / (1024 ** 3) - free_percent = 100 - usage.percent - - item = dict(meta={"mountpoint": mountpoint, "device": device}) - if free_Go < 1 or free_percent < 5: - item["status"] = "ERROR" - item["summary"] = ("diagnosis_diskusage_verylow", {"mountpoint": mountpoint, "device": device, "free_percent": free_percent}) - elif free_Go < 2 or free_percent < 10: - item["status"] = "WARNING" - item["summary"] = ("diagnosis_diskusage_low", {"mountpoint": mountpoint, "device": device, "free_percent": free_percent}) - else: - item["status"] = "SUCCESS" - item["summary"] = ("diagnosis_diskusage_ok", {"mountpoint": mountpoint, "device": device, "free_percent": free_percent}) - - yield item - -def main(args, env, loggers): - return DiskUsageDiagnoser(args, env, loggers).diagnose() diff --git a/data/hooks/diagnosis/50-systemresources.py b/data/hooks/diagnosis/50-systemresources.py new file mode 100644 index 000000000..3399c4682 --- /dev/null +++ b/data/hooks/diagnosis/50-systemresources.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +import os +import psutil + +from yunohost.diagnosis import Diagnoser + +class SystemResourcesDiagnoser(Diagnoser): + + id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] + cache_duration = 3600 * 24 + dependencies = [] + + def run(self): + + # + # 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) + item = dict(meta={"test": "ram"}) + infos = {"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: + item["status"] = "ERROR" + item["summary"] = ("diagnosis_ram_verylow", infos) + elif ram_available_abs_MB < 200 or ram_available_percent < 10: + item["status"] = "WARNING" + item["summary"] = ("diagnosis_ram_low", infos) + else: + item["status"] = "SUCCESS" + item["summary"] = ("diagnosis_ram_ok", infos) + print(item) + yield item + + # + # Swap + # + + swap = psutil.swap_memory() + swap_total_abs_MB = swap.total / (1024*1024) + item = dict(meta={"test": "swap"}) + infos = {"total_MB": swap_total_abs_MB} + if swap_total_abs_MB <= 0: + item["status"] = "ERROR" + item["summary"] = ("diagnosis_swap_none", infos) + elif swap_total_abs_MB <= 256: + item["status"] = "WARNING" + item["summary"] = ("diagnosis_swap_notsomuch", infos) + else: + item["status"] = "SUCCESS" + item["summary"] = ("diagnosis_swap_ok", infos) + print(item) + yield item + + # + # Disks usage + # + + disk_partitions = psutil.disk_partitions() + + for disk_partition in disk_partitions: + device = disk_partition.device + mountpoint = disk_partition.mountpoint + + usage = psutil.disk_usage(mountpoint) + free_abs_GB = usage.free / (1024 ** 3) + free_percent = 100 - usage.percent + + item = dict(meta={"mountpoint": mountpoint, "device": device}) + infos = {"mountpoint": mountpoint, "device": device, "free_abs_GB": free_abs_GB, "free_percent": free_percent} + if free_abs_GB < 1 or free_percent < 5: + item["status"] = "ERROR" + item["summary"] = ("diagnosis_diskusage_verylow", infos) + elif free_abs_GB < 2 or free_percent < 10: + item["status"] = "WARNING" + item["summary"] = ("diagnosis_diskusage_low", infos) + else: + item["status"] = "SUCCESS" + item["summary"] = ("diagnosis_diskusage_ok", infos) + + yield item + + +def main(args, env, loggers): + return SystemResourcesDiagnoser(args, env, loggers).diagnose() diff --git a/locales/en.json b/locales/en.json index f942d3dc4..40edb1425 100644 --- a/locales/en.json +++ b/locales/en.json @@ -185,9 +185,15 @@ "diagnosis_dns_discrepancy": "According to the recommended DNS configuration, the value for the DNS record with type {0} and name {1} should be {2}, not {3}.", "diagnosis_services_good_status": "Service {service} is {status} as expected!", "diagnosis_services_bad_status": "Service {service} is {status} :/", - "diagnosis_diskusage_verylow": "Storage {mountpoint} (on device {device}) has only {free_percent}% space remaining. You should really consider cleaning up some space.", - "diagnosis_diskusage_low": "Storage {mountpoint} (on device {device}) has only {free_percent}% space remaining. Be careful", - "diagnosis_diskusage_ok": "Storage {mountpoint} (on device {device}) still has {free_percent}% space left!", + "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_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_regenconf_allgood": "All configurations files are in line with the recommended configuration!", "diagnosis_regenconf_manually_modified": "Configuration file {file} was manually modified.", "diagnosis_regenconf_manually_modified_details": "This is probably OK as long as you know what you're doing ;) !", @@ -201,7 +207,7 @@ "diagnosis_description_ip": "Internet connectivity", "diagnosis_description_dnsrecords": "DNS records", "diagnosis_description_services": "Services status check", - "diagnosis_description_diskusage": "Disk usage", + "diagnosis_description_systemresources": "System resources", "diagnosis_description_ports": "Ports exposure", "diagnosis_description_http": "HTTP exposure", "diagnosis_description_regenconf": "System configurations",