Skip to content

Commit

Permalink
disk-usage-report: Add system mounts and bricks disk usage
Browse files Browse the repository at this point in the history
Signed-off-by: Prashant D pdhange@redhat.com
  • Loading branch information
Prashant D committed Oct 9, 2017
1 parent ebb4b97 commit 2ee86a6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
33 changes: 33 additions & 0 deletions glusterhealth/reports/disk_usage.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions glusterhealth/reports/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 2ee86a6

Please sign in to comment.