summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.server.scripts
diff options
context:
space:
mode:
authorTim <timothyasir@gluster.com>2011-06-01 15:04:24 +0530
committerTim <timothyasir@gluster.com>2011-06-01 15:04:24 +0530
commitcadc1886157e45a216c49de4c94ebf42d0f0b4ec (patch)
treee5c8e4933bf7d7fdb1404a2b0f08ae62c56c4dd3 /src/com.gluster.storage.management.server.scripts
parent438bcdcdfc72883d368133114cc38590a4a852d3 (diff)
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-xsrc/com.gluster.storage.management.server.scripts/src/get_rrd_memory_details.py59
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()