From 2ee86a6a1874ebc24a9235e8832d2f3b55348c9a Mon Sep 17 00:00:00 2001 From: Prashant D Date: Mon, 9 Oct 2017 16:23:35 +1100 Subject: [PATCH] disk-usage-report: Add system mounts and bricks disk usage Signed-off-by: Prashant D pdhange@redhat.com --- glusterhealth/reports/disk_usage.py | 33 +++++++++++++++++++++++++++++ glusterhealth/reports/utils.py | 28 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 glusterhealth/reports/disk_usage.py diff --git a/glusterhealth/reports/disk_usage.py b/glusterhealth/reports/disk_usage.py new file mode 100644 index 0000000..7deb420 --- /dev/null +++ b/glusterhealth/reports/disk_usage.py @@ -0,0 +1,33 @@ +# +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of gluster-health-report project which is a +# subproject of GlusterFS ( www.gluster.org) +# +# This file is licensed to you under your choice of the GNU Lesser +# General Public License, version 3 or any later version (LGPLv3 or +# later), or the GNU General Public License, version 2 (GPLv2), in all +# cases as published by the Free Software Foundation. + +import logging +from utils import get_disk_usage_details + +def check_disk_usage_percetage(ctx, path, percentage=0): + out = get_disk_usage_details(path) + if out is None: + return + if out.percentage: + used_percent = int(out.percentage.split('%')[0]) + if used_percent >= percentage: + ctx.notok("Disk used percentage for \'"+ path +"\' is exceeding "+ str(percentage) +"%, consider deleting unneccesary data") + else: + ctx.ok("Disk used percentage for \'"+ path +"\' is " + str(used_percent) +"%") + +def report_system_mounts_disk_usage(ctx): + check_disk_usage_percetage(ctx, "/", 90) + check_disk_usage_percetage(ctx, "/var", 90) + check_disk_usage_percetage(ctx, "/tmp", 90) + +def report_brick_disk_usage(ctx): + # ToDo : Add brick disk usage report + pass diff --git a/glusterhealth/reports/utils.py b/glusterhealth/reports/utils.py index 3ac89a7..ee0c94c 100644 --- a/glusterhealth/reports/utils.py +++ b/glusterhealth/reports/utils.py @@ -9,6 +9,7 @@ # later), or the GNU General Public License, version 2 (GPLv2), in all # cases as published by the Free Software Foundation. +import logging import re from subprocess import Popen, PIPE @@ -107,3 +108,30 @@ def process_log_file(path, callback, filterfunc=lambda l: True): if filterfunc(line): pline = parse_log_line(line) callback(pline) + +class DiskUsage(object): + def __init__(self, device, size, used, available, percentage, mountpoint): + self.device = device + self.size = size + self.used = used + self.available = available + self.percentage = percentage + self.mountpoint = mountpoint + + +def get_disk_usage_details(path): + if path is None: + return + cmd = ["df", path] + try: + out = command_output(cmd) + device, size, used, available, percentage, mountpoint = \ + out.split("\n")[1].split() + + return DiskUsage(device, size, used, available, percentage, mountpoint) + except CommandError as e: + logging.warning("Disk usage: \n" + out) + logging.warn(ctx.lf("disk usage failed", + error_code=e[0], + error=e[1])) + return None