/[ps-trend]/ps2rrd.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /ps2rrd.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Tue Jul 14 22:41:33 2009 UTC revision 9 by dpavlin, Fri Jul 17 10:34:42 2009 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
7  use RRD::Simple;  use RRD::Simple;
8  use DateTime;  use POSIX qw/mktime/;
9    
10    my $debug = 0;
11    my $zoom = 2;
12    
13  my $veids;  my $veids;
14  my $vsz;  my $vsz;
15    
16  my $too_small = 64;     # M  my $too_small = 16;     # M
17  $too_small *= 1024; # k  $too_small *= 1024; # k
18    
19  sub count {  sub count {
20          my $file = shift;          my $file = shift;
21          open(my $fh, '<', $file) || die "$file: $!";          open(my $fh, '<', $file) || die "$file: $!";
22          warn "# $file ", -s $file, $/;  
23            print STDERR ".";
24    
25            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)};
26    
27            warn "# $file ", -s $file, " bytes [$t]\n" if $debug;
28    
29          my $cols = <$fh>;          my $cols = <$fh>;
30          $cols =~ s/^\s+//;          $cols =~ s/^\s+//;
# Line 26  sub count { Line 34  sub count {
34          $cp->{$c[$_]} = $_ foreach 0 .. $#c;          $cp->{$c[$_]} = $_ foreach 0 .. $#c;
35          our @r;          our @r;
36          sub c {          sub c {
37                    return $r[ $cp->{$_[0]} ];      # XXX speedup
38    
39                  my $name = shift;                  my $name = shift;
40                  my $n = $cp->{$name};                  my $n = $cp->{$name};
41                  die "no column $name in ",dump( $cp ) unless defined $n;                  die "no column $name in ",dump( $cp ) unless defined $n;
# Line 43  sub count { Line 53  sub count {
53    
54                  my $s = c('VSZ');                  my $s = c('VSZ');
55                  if ( $s < $too_small ) {                  if ( $s < $too_small ) {
56                          $vsz->{$file}->{$veid}+= $s * 1024;                          $vsz->{$t}->{$veid}+= $s * 1024;
57                  } else {                  } else {
58                          my $cmd = c('COMMAND');                          my $cmd = c('COMMAND');
59                          $cmd =~ s{-.+$}{};                          $cmd =~ s{-.+$}{};
# Line 53  sub count { Line 63  sub count {
63                          $cmd =~ s{\W+}{_}g;                          $cmd =~ s{\W+}{_}g;
64                          $veid .= '-' . $cmd;                          $veid .= '-' . $cmd;
65                          $veid = substr($veid,0,16);                          $veid = substr($veid,0,16);
66                          $vsz->{$file}->{$veid}+= $s * 1024;                          $vsz->{$t}->{$veid}+= $s * 1024;
67                  }                  }
68                  $veids->{$veid}++;                  $veids->{$veid}++;
69          }          }
70    
71  }  }
72    
73    print STDERR "reading ps dumps";
74    
75  count $_ foreach @ARGV;  count $_ foreach @ARGV;
76    
77  print "VSZ: ",dump( $vsz );  #print "VSZ: ",dump( $vsz );
78    
79  my @veids = keys %$veids;  my @veids = keys %$veids;
80  warn "# veids = ",dump( sort @veids );  warn "# veids = ",dump( sort @veids );
81    
82  my $rrd = RRD::Simple->new( file => "ps.rrd" );  my $rrd_file = 'ps.rrd';
83  $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );  unlink $rrd_file if -e $rrd_file;
84    
85  foreach my $file ( sort keys %$vsz ) {  my $rrd = RRD::Simple->new( file => $rrd_file );
86          my $t = (stat($file))[9];  $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );
         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";  
         }  
87    
88          #warn "## ",dump( %{ $vsz->{$file} } );  foreach my $t ( sort keys %$vsz ) {
89            print STDERR ".";
90    #       warn "## ",dump( %{ $vsz->{$t} } );
91    
92          eval {          eval {
93                  $rrd->update($t->epoch, map {                  $rrd->update($t, map {
94                          ( $_ => $vsz->{$file}->{$_} )                          ( $_ => $vsz->{$t}->{$_} )
95                  } @veids );                  } @veids );
96          };          };
97          warn "SKIP $t: $@\n" if $@;          warn "SKIP $t: $@\n" if $@;
# Line 99  $rrd->graph( Line 103  $rrd->graph(
103          periods => [ qw/hour 6hour 12hour day week month year 3years/ ],          periods => [ qw/hour 6hour 12hour day week month year 3years/ ],
104          extended_legend => 1,          extended_legend => 1,
105          title => "memory > $too_small K",          title => "memory > $too_small K",
106          width => 500,          width =>  500 * $zoom,
107          height => 200,          height => 200 * $zoom,
108  );  );
109    

Legend:
Removed from v.2  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.26