diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/com.gluster.storage.management.server.scripts/src/get_rrd_net_details.py | 52 | ||||
| -rwxr-xr-x | src/com.gluster.storage.management.server.scripts/src/rrd_net.pl | 73 |
2 files changed, 125 insertions, 0 deletions
diff --git a/src/com.gluster.storage.management.server.scripts/src/get_rrd_net_details.py b/src/com.gluster.storage.management.server.scripts/src/get_rrd_net_details.py new file mode 100755 index 00000000..01777a9b --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/get_rrd_net_details.py @@ -0,0 +1,52 @@ +#!/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 +from XmlHandler import ResponseXml +import Utils + +def main(): + if len(sys.argv) != 3: + sys.stderr.write("usage: %s <DEVICE> <PERIOD>\n" % os.path.basename(sys.argv[0])) + sys.exit(-1) + + device = sys.argv[0] + period = sys.argv[1] + + rs = ResponseXml() + command = "rrdtool xport --start -%s \ + DEF:received=/var/lib/rrd/network-%s.rrd:received:AVERAGE \ + DEF:transmitted=/var/lib/rrd/network-%s.rrd:transmitted:AVERAGE \ + CDEF:total=received,transmitted,+ \ + XPORT:received:received \ + XPORT:transmitted:transmitted \ + XPORT:total:total" % (period, device, device) + rv = Utils.runCommand(command, output=True, root=True) + message = Utils.stripEmptyLines(rv["Stdout"]) + if rv["Stderr"]: + error = Utils.stripEmptyLines(rv["Stderr"]) + message += "Error: [%s]" % (error) + Utils.log("failed to get RRD information of device %s" % file) + rs.appendTagRoute("status.code", rv["Status"]) + rs.appendTagRoute("status.message", message) + print rs.toxml() + print rv["Stdout"] + sys.exit(0) + +if __name__ == "__main__": + main() diff --git a/src/com.gluster.storage.management.server.scripts/src/rrd_net.pl b/src/com.gluster.storage.management.server.scripts/src/rrd_net.pl new file mode 100755 index 00000000..61187487 --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/rrd_net.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +use RRDs; + +my $rrdlog = '/var/lib/rrd'; +my $graphs = '/var/lib/rrd'; + +updatenetdata(); +#updatenetgraph('day'); +#updatenetgraph('week'); +#updatenetgraph('month'); +#updatenetgraph('year'); + +sub updatenetgraph { + my $period = $_[0]; + + foreach $rrdfile (<$rrdlog/network-*.rrd>) { + RRDs::graph ("$graphs/network-$device-$period.png", + "--start", "-1$period", "-aPNG", "-i", "-z", + "--alt-y-grid", "-w 300", "-h 50", "-l 0", "-u 100", "-r", + "--color", "SHADEA#FFFFFF", + "--color", "SHADEB#FFFFFF", + "--color", "BACK#FFFFFF", + "-t $device load per $period", + "DEF:received=$rrdfile:received:AVERAGE", + "DEF:transmitted=$rrdfile:transmitted:AVERAGE", + + "CDEF:total=received,transmitted,+,+", + "CDEF:receivedpct=100,received,total,/,*", + "CDEF:transmittedpct=100,transmitted,total,/,*", + + "AREA:receivedpct#0000FF:received load\\j", + "STACK:transmittedpct#FF0000:transmitted load\\j"); + $ERROR = RRDs::error; + print "Error in RRD::graph for network $device: $ERROR\n" if $ERROR; + } +} + +sub updatenetdata { + open NETDEV, "/proc/net/dev"; + while (<NETDEV>) { + chomp; + s/^\s+//; # remove left side whitespaces + /:\s/ or next; # if input line contains ':' else continue + next if /^lo:\s/; # continue if input line starts with 'lo:' + + @tokens = split /\s+/; + @name = split(/:/, $tokens[0]); + $device = $name[0]; + + #print "$device, $tokens[1], $tokens[9]\n"; + + if ( ! -e "$rrdlog/network-$device.rrd") { + RRDs::create ("$rrdlog/network-$device.rrd", "--step=300", + "DS:received:COUNTER:600:0:U", + "DS:transmitted:COUNTER:600:0:U", + + "RRA:AVERAGE:0.5:1:576", + "RRA:AVERAGE:0.5:6:672", + "RRA:AVERAGE:0.5:24:732", + "RRA:AVERAGE:0.5:144:1460"); + $ERROR = RRDs::error; + print "Error in RRD::create for device $device: $ERROR\n" if $ERROR; + } + + RRDs::update ("$rrdlog/network-$device.rrd", + "-t", "received:transmitted", + "N:$tokens[1]:$tokens[9]"); + $ERROR = RRDs::error; + print "Error in RRD::update for net: $ERROR\n" if $ERROR; + } + close NETDEV +} |
