--- ps2rrd.pl 2009/07/14 22:41:33 2 +++ ps2rrd.pl 2009/07/16 19:13:01 6 @@ -7,16 +7,33 @@ use RRD::Simple; use DateTime; +my $debug = 0; +my $zoom = 2; + my $veids; my $vsz; -my $too_small = 64; # M +my $too_small = 16; # M $too_small *= 1024; # k sub count { my $file = shift; open(my $fh, '<', $file) || die "$file: $!"; - warn "# $file ", -s $file, $/; + + print STDERR "."; + + my $t = (stat($file))[9]; + if ( $file =~ m{(\d\d\d\d)-(\d\d)-(\d\d)/(\d\d)(\d\d)} ) { + $t = new DateTime( + year => $1, + month => $2, + day => $3, + hour => $4, + minute => $5, + )->epoch; + } + + warn "# $file ", -s $file, " bytes [$t]\n" if $debug; my $cols = <$fh>; $cols =~ s/^\s+//; @@ -43,7 +60,7 @@ my $s = c('VSZ'); if ( $s < $too_small ) { - $vsz->{$file}->{$veid}+= $s * 1024; + $vsz->{$t}->{$veid}+= $s * 1024; } else { my $cmd = c('COMMAND'); $cmd =~ s{-.+$}{}; @@ -53,41 +70,35 @@ $cmd =~ s{\W+}{_}g; $veid .= '-' . $cmd; $veid = substr($veid,0,16); - $vsz->{$file}->{$veid}+= $s * 1024; + $vsz->{$t}->{$veid}+= $s * 1024; } $veids->{$veid}++; } } +print STDERR "reading ps dumps"; + count $_ foreach @ARGV; -print "VSZ: ",dump( $vsz ); +#print "VSZ: ",dump( $vsz ); my @veids = keys %$veids; warn "# veids = ",dump( sort @veids ); -my $rrd = RRD::Simple->new( file => "ps.rrd" ); -$rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids ); +my $rrd_file = 'ps.rrd'; +unlink $rrd_file if -e $rrd_file; -foreach my $file ( sort keys %$vsz ) { - my $t = (stat($file))[9]; - if ( $file =~ m{(\d\d\d\d)-(\d\d)-(\d\d)/(\d\d)(\d\d)} ) { - $t = new DateTime( - year => $1, - month => $2, - day => $3, - hour => $4, - minute => $5, - ); - warn "+ $t\n"; - } +my $rrd = RRD::Simple->new( file => $rrd_file ); +$rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids ); - #warn "## ",dump( %{ $vsz->{$file} } ); +foreach my $t ( sort keys %$vsz ) { + print STDERR "."; +# warn "## ",dump( %{ $vsz->{$t} } ); eval { - $rrd->update($t->epoch, map { - ( $_ => $vsz->{$file}->{$_} ) + $rrd->update($t, map { + ( $_ => $vsz->{$t}->{$_} ) } @veids ); }; warn "SKIP $t: $@\n" if $@; @@ -99,7 +110,7 @@ periods => [ qw/hour 6hour 12hour day week month year 3years/ ], extended_legend => 1, title => "memory > $too_small K", - width => 500, - height => 200, + width => 500 * $zoom, + height => 200 * $zoom, );