diff options
| author | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-06-01 04:24:28 -0700 |
|---|---|---|
| committer | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-06-01 04:24:28 -0700 |
| commit | eecdc685f935510142c0ea0f81faf5406b85820f (patch) | |
| tree | ae6ca9de4f6a34318aa4be63f0b27d35ef4921d9 /src/com.gluster.storage.management.server.scripts | |
| parent | 686ab20fe2823b3e1507cb8415a9f52d781a1f5c (diff) | |
| parent | cadc1886157e45a216c49de4c94ebf42d0f0b4ec (diff) | |
Merge pull request #46 from TimothyAsir/master
Added get_rrd_memory_details.py file to get memory details from rrd.
Diffstat (limited to 'src/com.gluster.storage.management.server.scripts')
| -rwxr-xr-x | src/com.gluster.storage.management.server.scripts/src/get_rrd_memory_details.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/com.gluster.storage.management.server.scripts/src/get_rrd_memory_details.py b/src/com.gluster.storage.management.server.scripts/src/get_rrd_memory_details.py new file mode 100755 index 00000000..4d33381b --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/get_rrd_memory_details.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# Copyright (C) 2010 Gluster, Inc. <http://www.gluster.com> +# This file is part of Gluster Storage Platform. +# +# 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 +# <http://www.gnu.org/licenses/>. +import os +import sys +import syslog +from XmlHandler import ResponseXml +import Utils +import Common + +def getMemData(period): + memRrdFile = "/var/lib/rrd/mem.rrd" + rs = ResponseXml() + command = ["rrdtool", "xport", "--start", "-1%s" % period, + "DEF:used=%s:memused:AVERAGE" % memRrdFile, + "DEF:free=%s:memfree:AVERAGE" % memRrdFile, + "DEF:cache=%s:memcache:AVERAGE" % memRrdFile, + "CDEF:total=used,free,+", + "XPORT:used:'used'", + "XPORT:free:'free'", + "XPORT:cache:'cache'", + "XPORT:total:'total'"] + + rv = Utils.runCommandFG(command, stdout=True, root=True) + message = Common.stripEmptyLines(rv["Stdout"]) + if rv["Stderr"]: + error = Common.stripEmptyLines(rv["Stderr"]) + message += "Error: [%s]" % (error) + Common.log(syslog.LOG_ERR, "failed to create RRD file for memory usages %s" % file) + rs.appendTagRoute("status.code", rv["Status"]) + rs.appendTagRoute("status.message", message) + return rs.toxml() + return rv["Stdout"] + +def main(): + if len(sys.argv) != 2: + print >> sys.stderr, "usage: %s <period>" % sys.argv[0] + sys.exit(-1) + + period = sys.argv[1] + print getMemData(period) + sys.exit(0) + +if __name__ == "__main__": + main() |
