Created
November 17, 2011 19:34
-
-
Save fearphage/1374196 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| # | |
| # copyright Martin Pot 2003 | |
| # http://martybugs.net/linux/hddtemp.cgi | |
| # | |
| # rrd_hddtemp.pl | |
| # | |
| # Abusing this script to graph Opera memory usage | |
| # 13-03-2010 | |
| # Remco Lanting | |
| # | |
| use RRDs; | |
| # define location of rrdtool databases | |
| my $rrd = '/home/remco/cron'; | |
| # define location of images | |
| my $img = '/var/www'; | |
| # process data for each specified HDD (add/delete as required) | |
| # don't forget to add/remove from createGraph as well! | |
| &ProcessGraph("VmPeak", "Peak virtual memory usage"); | |
| &ProcessGraph("VmSize", "Current virtual memory usage"); | |
| ##&ProcessGraph("VmLck", "Locked memory"); | |
| &ProcessGraph("VmHWM", "Peak resident memory usage"); | |
| &ProcessGraph("VmRSS", "Current resident memory usage"); | |
| &ProcessGraph("VmData", "Data segment memory size"); | |
| ##&ProcessGraph("VmStk", "Stack segment memory size"); | |
| ##&ProcessGraph("VmExe", "Text segment memory size"); | |
| # Less than 50MB, not that interesting | |
| #&ProcessGraph("VmLib", "Shared library code size"); | |
| ##&ProcessGraph("VmPTE", "Page table entry size"); | |
| sub ProcessGraph | |
| { | |
| # process Graph | |
| # inputs: $_[0]: stat to grep for | |
| # $_[1]: description, although not used | |
| my $stattype = $_[0]; | |
| my $s = `fuser -v /home/remco/.opera/lock 2>&1`; | |
| my @lines = split(/\n/,$s); | |
| shift(@lines); shift(@lines); | |
| $size = @lines; | |
| my $pid = 0; | |
| for ($i=0; $i<$size; $i++) { | |
| $l = $lines[$i]; | |
| $l =~ s/^\s+//; $l =~ s/\s+$//; | |
| my @words = split(' ',$l); | |
| if ($words[3] eq 'opera') { | |
| $pid = $words[1]; | |
| break; | |
| } | |
| } | |
| if ($pid <= 0) { | |
| return 1; | |
| } | |
| my $memstring = `grep $stattype /proc/$pid/status`; | |
| my @memwords = split(' ',$memstring); | |
| my $memory = $memwords[1] * 1024; | |
| print "$_[1] ($_[0]): $memory B\n"; | |
| # if rrdtool database doesn't exist, create it | |
| if (! -e "$rrd/opera_$_[0].rrd") | |
| { | |
| print "creating rrd database for Opera_$_[0]...\n"; | |
| RRDs::create "$rrd/opera_$_[0].rrd", | |
| "-s 300", | |
| "DS:mem:GAUGE: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"; | |
| } | |
| # insert value into rrd | |
| RRDs::update "$rrd/opera_$_[0].rrd", | |
| "-t", "mem", | |
| "N:$memory"; | |
| } | |
| &CreateGraph("", "day"); | |
| &CreateGraph("", "week"); | |
| &CreateGraph("", "month"); | |
| &CreateGraph("", "year"); | |
| sub CreateGraph | |
| { | |
| # creates graph | |
| # inputs: $_[0]: no longer used | |
| # $_[1]: interval (ie, day, week, month, year) | |
| # $_[2]: description | |
| RRDs::graph "$img/opera-$_[1].png", | |
| "--lazy", | |
| "-s -1$_[1]", | |
| "-t Opera memory usage", | |
| "-h", "400", "-w", "800", | |
| "--full-size-mode", | |
| "-a", "PNG", | |
| "-v Memory usage", | |
| "--units-exponent", "6", | |
| "--base", "1024", | |
| "--lower-limit", "0", | |
| "--slope-mode", | |
| #default type is LINE2 | |
| #Peak virtual memory usage (VmPeak): 2030.4296875 mB | |
| "DEF:VmPeak=$rrd/opera_VmPeak.rrd:mem:AVERAGE", | |
| "LINE2:VmPeak#ea644a:Peak virtual memory usage ", | |
| "GPRINT:VmPeak:MIN:Min\\: %6.2lf%s", | |
| "GPRINT:VmPeak:MAX:Max\\: %6.2lf%s", | |
| "GPRINT:VmPeak:AVERAGE:Avg\\: %6.2lf%s", | |
| "GPRINT:VmPeak:LAST:Current\\: %6.2lf%s\\n", | |
| #Current virtual memory usage (VmSize): 2017.04296875 mB | |
| "DEF:VmSize=$rrd/opera_VmSize.rrd:mem:AVERAGE", | |
| "LINE2:VmSize#ec9d48:Current virtual memory usage ", | |
| "GPRINT:VmSize:MIN:Min\\: %6.2lf%s", | |
| "GPRINT:VmSize:MAX:Max\\: %6.2lf%s", | |
| "GPRINT:VmSize:AVERAGE:Avg\\: %6.2lf%s", | |
| "GPRINT:VmSize:LAST:Current\\: %6.2lf%s\\n", | |
| #Peak resident memory usage (VmHWM): 469.9765625 mB | |
| "DEF:VmHWM=$rrd/opera_VmHWM.rrd:mem:AVERAGE", | |
| "LINE2:VmHWM#ecd748:Peak resident memory usage ", | |
| "GPRINT:VmHWM:MIN:Min\\: %6.2lf%s", | |
| "GPRINT:VmHWM:MAX:Max\\: %6.2lf%s", | |
| "GPRINT:VmHWM:AVERAGE:Avg\\: %6.2lf%s", | |
| "GPRINT:VmHWM:LAST:Current\\: %6.2lf%s\\n", | |
| #Current resident memory usage (VmRSS): 469.97265625 mB | |
| "DEF:VmRSS=$rrd/opera_VmRSS.rrd:mem:AVERAGE", | |
| "LINE2:VmRSS#54ec48:Current resident memory usage", | |
| "GPRINT:VmRSS:MIN:Min\\: %6.2lf%s", | |
| "GPRINT:VmRSS:MAX:Max\\: %6.2lf%s", | |
| "GPRINT:VmRSS:AVERAGE:Avg\\: %6.2lf%s", | |
| "GPRINT:VmRSS:LAST:Current\\: %6.2lf%s\\n", | |
| #Size of data segment (VmData): VmData: 1942060 kB | |
| "DEF:VmData=$rrd/opera_VmData.rrd:mem:AVERAGE", | |
| "LINE2:VmData#48c4ec:Size of data segment ", | |
| "GPRINT:VmData:MIN:Min\\: %6.2lf%s", | |
| "GPRINT:VmData:MAX:Max\\: %6.2lf%s", | |
| "GPRINT:VmData:AVERAGE:Avg\\: %6.2lf%s", | |
| "GPRINT:VmData:LAST:Current\\: %6.2lf%s\\n"; | |
| # extra colour for later use: #7648ec | |
| if ($ERROR = RRDs::error) { print "$0: unable to generate $_[1] graph: $ERROR\n"; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment