/[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 8 by dpavlin, Thu Jul 16 19:20:07 2009 UTC revision 11 by dpavlin, Fri Jul 17 13:25:34 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    use Getopt::Long;
10    
11  my $debug = 0;  my $debug = 0;
12  my $zoom = 2;  my $zoom = 2;
13    
14    my $only_veid;
15    my $too_small = 64;     # M
16    
17    GetOptions(
18            'debug!'   => \$debug,
19            'zoom=i'   => \$zoom,
20            'veid=i'   => \$only_veid,
21            'size=i'   => \$too_small,
22    );
23    
24    
25  my $veids;  my $veids;
26  my $vsz;  my $vsz;
27    
 my $too_small = 16;     # M  
28  $too_small *= 1024; # k  $too_small *= 1024; # k
29    
30  sub count {  sub count {
31          my $file = shift;          my $file = shift;
32          open(my $fh, '<', $file) || die "$file: $!";          open(my $fh, '<', $file) || die "$file: $!";
33    
34          print STDERR ".";          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)};
   
         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;  
         }  
35    
36          warn "# $file ", -s $file, " bytes [$t]\n" if $debug;          warn "# $file ", -s $file, " bytes [$t]\n" if $debug;
37    
# Line 58  sub count { Line 58  sub count {
58                  @r = split(/\s+/, $_, $#c + 1 );                  @r = split(/\s+/, $_, $#c + 1 );
59    
60                  my $veid = c('VEID');                  my $veid = c('VEID');
61                  $veid =~ s/^0$/hw/;                  next if defined $only_veid && $only_veid != $veid;
62                    $veid =~ s/^0$/0-hw/;
63    
64                  my $s = c('VSZ');                  my $s = c('VSZ');
65                  if ( $s < $too_small ) {                  if ( $s < $too_small ) {
66                          $vsz->{$t}->{$veid}+= $s * 1024;                          $vsz->{$t}->{$veid}+= $s * 1024;
67                            print STDERR ".";
68                  } else {                  } else {
69                          my $cmd = c('COMMAND');                          my $cmd = c('COMMAND');
70                          $cmd =~ s{-.+$}{};                          $cmd =~ s{-.+$}{};
# Line 73  sub count { Line 75  sub count {
75                          $veid .= '-' . $cmd;                          $veid .= '-' . $cmd;
76                          $veid = substr($veid,0,16);                          $veid = substr($veid,0,16);
77                          $vsz->{$t}->{$veid}+= $s * 1024;                          $vsz->{$t}->{$veid}+= $s * 1024;
78                            print STDERR substr($cmd,0,1);
79                  }                  }
80                  $veids->{$veid}++;                  $veids->{$veid}++;
81          }          }
82    
83  }  }
84    
85  print STDERR "reading ps dumps";  print STDERR "parsing ps with grouping < $too_small k";
86    
87  count $_ foreach @ARGV;  count $_ foreach @ARGV;
88    
89  #print "VSZ: ",dump( $vsz );  #print "VSZ: ",dump( $vsz );
90    
91  my @veids = keys %$veids;  my @veids = sort keys %$veids;
92  warn "# veids = ",dump( sort @veids );  warn "# veids = ",dump( @veids );
93    
94  my $rrd_file = 'ps.rrd';  my $rrd_file = 'ps.rrd';
95  unlink $rrd_file if -e $rrd_file;  unlink $rrd_file if -e $rrd_file;
96    
97    my @t = sort keys %$vsz;
98    
99    print "\ndrawing $#t intervals ", $t[0], " - ", $t[$#t];
100    
101  my $rrd = RRD::Simple->new( file => $rrd_file );  my $rrd = RRD::Simple->new( file => $rrd_file );
102  $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );  $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );
103    
104  foreach my $t ( sort keys %$vsz ) {  foreach my $t ( @t ) {
105          print STDERR ".";          print STDERR ".";
106  #       warn "## ",dump( %{ $vsz->{$t} } );  #       warn "## ",dump( %{ $vsz->{$t} } );
107    

Legend:
Removed from v.8  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26