From c024c9197fbe46fcf988740e8379b34267eceb24 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 4 Aug 2011 14:22:28 +0530 Subject: Enhanced get_server_details.py to provide disk-space-in-use using df command in case of HAL failed to give. Updated Utils.py to return None on ZeroDivideError during cpu percentage calculation. --- .../src/DiskUtils.py | 14 ++++++++++++-- .../src/Utils.py | 6 +++++- .../src/get_rrd_cpu_details.py | 18 +++--------------- 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src/com.gluster.storage.management.gateway.scripts') diff --git a/src/com.gluster.storage.management.gateway.scripts/src/DiskUtils.py b/src/com.gluster.storage.management.gateway.scripts/src/DiskUtils.py index a0e5d802..aa77cebb 100644 --- a/src/com.gluster.storage.management.gateway.scripts/src/DiskUtils.py +++ b/src/com.gluster.storage.management.gateway.scripts/src/DiskUtils.py @@ -256,7 +256,17 @@ def getDiskInfo(diskDeviceList=None): disk["FsVersion"] = None disk["MountPoint"] = None disk["ReadOnlyAccess"] = None - disk["SpaceInUse"] = None + + spaceInUse = None + rv = Utils.runCommand("df %s" % (disk["Device"]), output=True, root=True) + if rv["Status"] == 0: + try: + spaceInUse = long(rv["Stdout"].split("\n")[1].split()[2]) / 1024 + except IndexError: + pass + except ValueError: + pass + disk["SpaceInUse"] = spaceInUse partitionUdiList = halManager.FindDeviceStringMatch("info.parent", udi) if isDiskInFormatting(disk["Device"]): @@ -315,7 +325,7 @@ def getDiskInfo(diskDeviceList=None): disk["ReadOnlyAccess"] = str(partitionHalDevice.GetProperty('volume.is_mounted_read_only')) if not disk["Size"]: disk["Size"] = long(partitionHalDevice.GetProperty('volume.size')) / 1024**2 - disk["SpaceInUse"] = used + #disk["SpaceInUse"] = used continue partition = {} diff --git a/src/com.gluster.storage.management.gateway.scripts/src/Utils.py b/src/com.gluster.storage.management.gateway.scripts/src/Utils.py index 980e7937..a212f104 100644 --- a/src/com.gluster.storage.management.gateway.scripts/src/Utils.py +++ b/src/com.gluster.storage.management.gateway.scripts/src/Utils.py @@ -409,7 +409,11 @@ def getCpuUsageAvg(): if not (st1 and st2): return None delta = [st2[i] - st1[i] for i in range(len(st1))] - cpuPercent = sum(delta[:3]) / delta[3] * 100.0 + try: + cpuPercent = sum(delta[:3]) / delta[3] * 100.0 + except ZeroDivisionError, e: + log("failed to find cpu percentage:%s" % str(e)) + return None return str('%.4f' % cpuPercent) def getLoadavg(): diff --git a/src/com.gluster.storage.management.gateway.scripts/src/get_rrd_cpu_details.py b/src/com.gluster.storage.management.gateway.scripts/src/get_rrd_cpu_details.py index 8d2efd1a..e60d7199 100755 --- a/src/com.gluster.storage.management.gateway.scripts/src/get_rrd_cpu_details.py +++ b/src/com.gluster.storage.management.gateway.scripts/src/get_rrd_cpu_details.py @@ -1,20 +1,8 @@ #!/usr/bin/python -# Copyright (C) 2010 Gluster, Inc. -# This file is part of Gluster Storage Platform. +# Copyright (C) 2011 Gluster, Inc. +# This file is part of Gluster Management Gateway. # -# Gluster Storage Platform is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 3 of -# the License, or (at your option) any later version. -# -# Gluster Storage Platform is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . + import os import sys p1 = os.path.abspath(os.path.dirname(sys.argv[0])) -- cgit