mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Implement a first version for disk usage check
This commit is contained in:
parent
1019e95b1d
commit
24f9d475b8
2 changed files with 46 additions and 0 deletions
42
data/hooks/diagnosis/50-diskusage.py
Normal file
42
data/hooks/diagnosis/50-diskusage.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#!/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
|
||||||
|
|
||||||
|
def validate_args(self, args):
|
||||||
|
# TODO / FIXME Ugh do we really need this arg system
|
||||||
|
return {}
|
||||||
|
|
||||||
|
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()
|
|
@ -168,9 +168,13 @@
|
||||||
"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_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_good_status": "Service {service} is {status} as expected!",
|
||||||
"diagnosis_services_bad_status": "Service {service} is {status} :/",
|
"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_description_ip": "Internet connectivity",
|
"diagnosis_description_ip": "Internet connectivity",
|
||||||
"diagnosis_description_dnsrecords": "DNS records",
|
"diagnosis_description_dnsrecords": "DNS records",
|
||||||
"diagnosis_description_services": "Services status check",
|
"diagnosis_description_services": "Services status check",
|
||||||
|
"diagnosis_description_diskusage": "Disk usage",
|
||||||
"domain_cannot_remove_main": "Cannot remove main domain. Set a new main domain first",
|
"domain_cannot_remove_main": "Cannot remove main domain. Set a new main domain first",
|
||||||
"domain_cert_gen_failed": "Could not generate certificate",
|
"domain_cert_gen_failed": "Could not generate certificate",
|
||||||
"domain_created": "Domain created",
|
"domain_created": "Domain created",
|
||||||
|
|
Loading…
Add table
Reference in a new issue