--- ps2rrd.pl 2009/07/17 12:37:29 10 +++ ps2rrd.pl 2009/07/19 19:06:10 20 @@ -6,14 +6,31 @@ use Data::Dump qw/dump/; use RRD::Simple; use POSIX qw/mktime/; +use Getopt::Long; my $debug = 0; my $zoom = 2; +my $only_veid; +my $by_veid; +my $too_small = 64; # M +my $filter = qr{(apache|mysql|postgres|cgi-bin|SIP|ldap|zebra)}; + +my $use = 'VSZ'; + +GetOptions( + 'debug!' => \$debug, + 'zoom=i' => \$zoom, + 'only-veid=i' => \$only_veid, + 'by-veid!' => \$by_veid, + 'size=i' => \$too_small, + 'use=s' => \$use, +); + + my $veids; my $vsz; -my $too_small = 16; # M $too_small *= 1024; # k sub count { @@ -22,7 +39,8 @@ my $t = mktime( 0, $5, $4, $3, $2 - 1, $1 - 1900 ) if $file =~ m{(\d\d\d\d)-(\d\d)-(\d\d)/(\d\d)(\d\d)}; - warn "# $file ", -s $file, " bytes [$t]\n" if $debug; +# warn "# $file ", -s $file, " bytes [$t]\n" if $debug; + print STDERR "\n$file\t"; my $cols = <$fh>; $cols =~ s/^\s+//; @@ -47,14 +65,24 @@ @r = split(/\s+/, $_, $#c + 1 ); my $veid = c('VEID'); - $veid =~ s/^0$/hw/; + next if defined $only_veid && $only_veid != $veid; + $veid =~ s/^0$/_hw_0/; + + my $s = c($use); + my $cmd = c('COMMAND'); + if ( ! $by_veid && $cmd =~ $filter ) { + + $veid .= '-' . $1; + $vsz->{$t}->{$veid} += $s * 1024; + print STDERR uc(substr($1,0,1)); + + } elsif ( $s < $too_small || $by_veid ) { - my $s = c('VSZ'); - if ( $s < $too_small ) { $vsz->{$t}->{$veid}+= $s * 1024; print STDERR "."; + } else { - my $cmd = c('COMMAND'); + $cmd =~ s{-.+$}{}; $cmd =~ s{^/\S+/(\w+?)}{$1}; $cmd =~ s{^\w+ /\S+/(\w+?)}{$1}; @@ -70,22 +98,26 @@ } -print STDERR "reading ps dumps"; +print STDERR "parsing ps with grouping < $too_small k"; count $_ foreach @ARGV; #print "VSZ: ",dump( $vsz ); -my @veids = keys %$veids; -warn "# veids = ",dump( sort @veids ); +my @veids = sort keys %$veids; +warn "# veids = ",dump( @veids ); -my $rrd_file = 'ps.rrd'; +my $rrd_file = $use . '.rrd'; unlink $rrd_file if -e $rrd_file; +my @t = sort keys %$vsz; + +print "\ndrawing $#t intervals ", $t[0], " - ", $t[$#t]; + my $rrd = RRD::Simple->new( file => $rrd_file ); -$rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids ); +$rrd->create( map { ( $_ => 'GAUGE' ) } @veids ); -foreach my $t ( sort keys %$vsz ) { +foreach my $t ( @t ) { print STDERR "."; # warn "## ",dump( %{ $vsz->{$t} } ); @@ -102,7 +134,7 @@ source_drawtypes => [ map { $_ ? 'STACK' : 'AREA' } 0 .. $#veids ], periods => [ qw/hour 6hour 12hour day week month year 3years/ ], extended_legend => 1, - title => "memory > $too_small K", + title => "$use > $too_small K", width => 500 * $zoom, height => 200 * $zoom, );