diff options
Diffstat (limited to 'src/com.gluster.storage.management.server.scripts')
4 files changed, 240 insertions, 22 deletions
diff --git a/src/com.gluster.storage.management.server.scripts/src/get_rrd_cpu_details.py b/src/com.gluster.storage.management.server.scripts/src/get_rrd_cpu_details.py index 16670576..546aec31 100755 --- a/src/com.gluster.storage.management.server.scripts/src/get_rrd_cpu_details.py +++ b/src/com.gluster.storage.management.server.scripts/src/get_rrd_cpu_details.py @@ -23,13 +23,13 @@ import Utils def getCpuData(period): cpuRrdFile = "/var/lib/rrd/cpu.rrd" rs = ResponseXml() - command = ["rrdtool", "xport", "--start", "-1%s" % period, - "DEF:cpuuser=%s:user:AVERAGE" % cpuRrdFile, - "DEF:cpusystem=%s:system:AVERAGE" % cpuRrdFile, - "DEF:cpuidle=%s:idle:AVERAGE" % cpuRrdFile, - "XPORT:cpuuser:'user'", - "XPORT:cpusystem:'system'", - "XPORT:cpuidle:'idle'"] + command = "rrdtool xport --start -%s \ + DEF:cpuuser=%s:user:AVERAGE \ + DEF:cpusystem=%s:system:AVERAGE \ + CDEF:total=cpuuser,cpusystem,+ \ + XPORT:cpuuser:user \ + XPORT:cpusystem:system \ + XPORT:total:total" % (period, cpuRrdFile, cpuRrdFile) rv = Utils.runCommand(command, output=True, root=True) message = Utils.stripEmptyLines(rv["Stdout"]) 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 index 4d33381b..c165e57a 100755 --- 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 @@ -15,32 +15,67 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see # <http://www.gnu.org/licenses/>. + +# Input command: get_rrd_memory_details.py 1hour +# OUTPUT as bellow: +# <?xml version="1.0" encoding="ISO-8859-1"?> +# +# <xport> +# <meta> +# <start>1310455500</start> +# <step>300</step> +# <end>1310459100</end> +# <rows>13</rows> +# <columns>4</columns> +# <legend> +# <entry>memoryUsed</entry> +# <entry>memoryFree</entry> +# <entry>memoryCache</entry> +# <entry>totalMemory</entry> +# </legend> +# </meta> +# <data> +# <row><t>1310455500</t><v>1.9181091707e+06</v><v>1.5819754974e+06</v><v>1.2528146351e+06</v><v>3.5000846681e+06</v></row> +# <row><t>1310455800</t><v>1.9037555461e+06</v><v>1.5963191358e+06</v><v>1.2528521002e+06</v><v>3.5000746819e+06</v></row> +# <row><t>1310456100</t><v>1.9038003766e+06</v><v>1.5963538435e+06</v><v>1.2529487374e+06</v><v>3.5001542201e+06</v></row> +# <row><t>1310456400</t><v>1.9042611443e+06</v><v>1.5959639300e+06</v><v>1.2530286311e+06</v><v>3.5002250743e+06</v></row> +# <row><t>1310456700</t><v>1.9044356924e+06</v><v>1.5957328399e+06</v><v>1.2530492795e+06</v><v>3.5001685323e+06</v></row> +# <row><t>1310457000</t><v>1.9048233351e+06</v><v>1.5952823779e+06</v><v>1.2530540764e+06</v><v>3.5001057130e+06</v></row> +# <row><t>1310457300</t><v>1.9047911068e+06</v><v>1.5952553868e+06</v><v>1.2530601913e+06</v><v>3.5000464936e+06</v></row> +# <row><t>1310457600</t><v>1.9048929048e+06</v><v>1.5953391701e+06</v><v>1.2531675638e+06</v><v>3.5002320749e+06</v></row> +# <row><t>1310457900</t><v>1.9051587666e+06</v><v>1.5947842070e+06</v><v>1.2531049438e+06</v><v>3.4999429736e+06</v></row> +# <row><t>1310458200</t><v>1.9059319764e+06</v><v>1.5942797579e+06</v><v>1.2532148443e+06</v><v>3.5002117344e+06</v></row> +# <row><t>1310458500</t><v>1.9058528445e+06</v><v>1.5941925515e+06</v><v>1.2531962561e+06</v><v>3.5000453961e+06</v></row> +# <row><t>1310458800</t><v>NaN</v><v>NaN</v><v>NaN</v><v>NaN</v></row> +# <row><t>1310459100</t><v>NaN</v><v>NaN</v><v>NaN</v><v>NaN</v></row> +# </data> +# </xport> + 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'"] + command = "rrdtool xport --start -%s \ + DEF:free=%s:memfree:AVERAGE \ + DEF:used=%s:memused:AVERAGE \ + DEF:cache=%s:memcache:AVERAGE \ + CDEF:total=used,free,+ \ + XPORT:used:memoryUsed \ + XPORT:free:memoryFree \ + XPORT:cache:memoryCache \ + XPORT:total:totalMemory" % (period, memRrdFile, memRrdFile, memRrdFile) - rv = Utils.runCommandFG(command, stdout=True, root=True) - message = Common.stripEmptyLines(rv["Stdout"]) + rv = Utils.runCommand(command, output=True, root=True) + message = Utils.stripEmptyLines(rv["Stdout"]) if rv["Stderr"]: - error = Common.stripEmptyLines(rv["Stderr"]) + error = Utils.stripEmptyLines(rv["Stderr"]) message += "Error: [%s]" % (error) - Common.log(syslog.LOG_ERR, "failed to create RRD file for memory usages %s" % file) + Utils.log("failed to create RRD file for memory usages %s" % file) rs.appendTagRoute("status.code", rv["Status"]) rs.appendTagRoute("status.message", message) return rs.toxml() @@ -48,7 +83,7 @@ def getMemData(period): def main(): if len(sys.argv) != 2: - print >> sys.stderr, "usage: %s <period>" % sys.argv[0] + sys.stderr.write("usage: %s <period>\n" % os.path.basename(sys.argv[0])) sys.exit(-1) period = sys.argv[1] diff --git a/src/com.gluster.storage.management.server.scripts/src/rrd_cpu.pl b/src/com.gluster.storage.management.server.scripts/src/rrd_cpu.pl new file mode 100755 index 00000000..7b070812 --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/rrd_cpu.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +use RRDs; + +my $rrdlog = '/var/lib/rrd'; +my $graphs = '/var/lib/rrd'; + +updatecpudata(); +#updatecpugraph('day'); +#updatecpugraph('week'); +#updatecpugraph('month'); +#updatecpugraph('year'); + +sub updatecpugraph { + my $period = $_[0]; + + RRDs::graph ("$graphs/cpu-$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 cpu usage per $period", + "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE", + "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE", + "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE", + + "CDEF:total=user,system,idle,+,+", + "CDEF:userpct=100,user,total,/,*", + "CDEF:systempct=100,system,total,/,*", + "CDEF:idlepct=100,idle,total,/,*", + + "AREA:userpct#0000FF:User cpu usage\\j", + "STACK:systempct#FF0000:system cpu usage\\j", + "STACK:idlepct#00FF00:idle cpu usage\\j"); + + # "GPRINT:userpct:MAX:maximal user cpu\\:%3.2lf%%", + # "GPRINT:userpct:AVERAGE:average user cpu\\:%3.2lf%%", + # "GPRINT:userpct:LAST:current user cpu\\:%3.2lf%%\\j", + # "GPRINT:systempct:MAX:maximal system cpu\\:%3.2lf%%", + # "GPRINT:systempct:AVERAGE:average system cpu\\:%3.2lf%%", + # "GPRINT:systempct:LAST:current system cpu\\:%3.2lf%%\\j", + # "GPRINT:idlepct:MAX:maximal idle cpu\\:%3.2lf%%", + # "GPRINT:idlepct:AVERAGE:average idle cpu\\:%3.2lf%%", + # "GPRINT:idlepct:LAST:current idle cpu\\:%3.2lf%%\\j"); + $ERROR = RRDs::error; + print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR; +} + +sub updatecpudata { + if ( ! -e "$rrdlog/cpu.rrd") { + RRDs::create ("$rrdlog/cpu.rrd", "--step=300", + "DS:user:COUNTER:600:0:U", + "DS:system:COUNTER:600:0:U", + "DS:idle: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 cpu: $ERROR\n" if $ERROR; + } + + my ($cpu, $user, $nice, $system,$idle); + + open STAT, "/proc/stat"; + while(<STAT>) { + chomp; + /^cpu\s/ or next; + ($cpu, $user, $nice, $system, $idle) = split /\s+/; + last; + } + close STAT; + $user += $nice; + + RRDs::update ("$rrdlog/cpu.rrd", + "-t", "user:system:idle", + "N:$user:$system:$idle"); + $ERROR = RRDs::error; + print "Error in RRD::update for cpu: $ERROR\n" if $ERROR; + + print "N:$user:$system:$idle\n"; +} diff --git a/src/com.gluster.storage.management.server.scripts/src/rrd_mem.pl b/src/com.gluster.storage.management.server.scripts/src/rrd_mem.pl new file mode 100755 index 00000000..5db71ba5 --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/rrd_mem.pl @@ -0,0 +1,99 @@ +#!/usr/bin/perl + +use RRDs; + +my $rrdlog = '/var/lib/rrd'; +my $graphs = '/var/lib/rrd'; + +updatememdata (); +#updatememgraph ('day'); +#updatememgraph ('week'); +#updatememgraph ('month'); +#updatememgraph ('year'); + +sub updatememgraph { + my $period = $_[0]; + + RRDs::graph ("$graphs/memory-$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 memory usage per $period", + "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE", + "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE", + "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE", + "CDEF:total=used,free,+", + "CDEF:used1=used,buffer,cache,-,-", + "CDEF:usedpct=100,used1,total,/,*", + "CDEF:free1=total,used1,-", + "CDEF:cachepct=100,cache,total,/,*", + "CDEF:freepct=100,free1,total,/,*", + "AREA:usedpct#0000FF:used memory\\j", + "STACK:cachepct#FFFF00:cached memory\\j", + "STACK:freepct#00FF00:free memory\\j"); + $ERROR = RRDs::error; + print "Error in RRD::graph for mem: $ERROR\n" if $ERROR; + + RRDs::graph ("$graphs/swap-$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 swap usage per $period", + "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE", + "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE", + "CDEF:total=used,free,+", + "CDEF:usedpct=100,used,total,/,*", + "CDEF:freepct=100,free,total,/,*", + "AREA:usedpct#0000FF:used swap\\j", + "STACK:freepct#00FF00:free swap\\j"); + $ERROR = RRDs::error; + print "Error in RRD::graph for swap: $ERROR\n" if $ERROR; +} + +sub updatememdata { + my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree); + if ( ! -e "$rrdlog/mem.rrd") { + RRDs::create ("$rrdlog/mem.rrd", "--step=300", + "DS:memused:ABSOLUTE:600:0:U", + "DS:memfree:ABSOLUTE:600:0:U", + "DS:memcache:ABSOLUTE:600:0:U", + "DS:swapused:ABSOLUTE:600:0:U", + "DS:swapfree:ABSOLUTE: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 mem: $ERROR\n" if $ERROR; + } + + my @memdata = `free -b -o`; + + my $temp = $memdata[1]; + + chomp( $temp ); + my @tempa = split (/\s+/, $temp); + $memused = $tempa [2]; + $memfree = $tempa [3]; + $memshared = $tempa [4]; + $membuffers = $tempa [5]; + $memcache = $tempa [6]; + + $temp = $memdata[2]; + chomp( $temp ); + @tempa = split (/\s+/, $temp); + $swapused = $tempa [2]; + $swapfree = $tempa [3]; + + + RRDs::update ("$rrdlog/mem.rrd", + "-t", "memused:memfree:memcache:swapused:swapfree", + "N:$memused:$memfree:$memcache:$swapused:$swapfree"); + + $ERROR = RRDs::error; + print "Error in RRD::update for mem: $ERROR\n" if $ERROR; +} |
