/[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 10 by dpavlin, Fri Jul 17 12:37:29 2009 UTC revision 14 by dpavlin, Fri Jul 17 18:35:34 2009 UTC
# Line 6  use strict; Line 6  use strict;
6  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
7  use RRD::Simple;  use RRD::Simple;
8  use POSIX qw/mktime/;  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    my $filter = qr{(apache|mysql|postgres|cgi-bin|SIP)};
17    
18    GetOptions(
19            'debug!'   => \$debug,
20            'zoom=i'   => \$zoom,
21            'veid=i'   => \$only_veid,
22            'size=i'   => \$too_small,
23    );
24    
25    
26  my $veids;  my $veids;
27  my $vsz;  my $vsz;
28    
 my $too_small = 16;     # M  
29  $too_small *= 1024; # k  $too_small *= 1024; # k
30    
31  sub count {  sub count {
# Line 22  sub count { Line 34  sub count {
34    
35          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 = mktime( 0, $5, $4, $3, $2 - 1, $1 - 1900 ) if $file =~ m{(\d\d\d\d)-(\d\d)-(\d\d)/(\d\d)(\d\d)};
36    
37          warn "# $file ", -s $file, " bytes [$t]\n" if $debug;  #       warn "# $file ", -s $file, " bytes [$t]\n" if $debug;
38            print STDERR "\n$file\t";
39    
40          my $cols = <$fh>;          my $cols = <$fh>;
41          $cols =~ s/^\s+//;          $cols =~ s/^\s+//;
# Line 47  sub count { Line 60  sub count {
60                  @r = split(/\s+/, $_, $#c + 1 );                  @r = split(/\s+/, $_, $#c + 1 );
61    
62                  my $veid = c('VEID');                  my $veid = c('VEID');
63                  $veid =~ s/^0$/hw/;                  next if defined $only_veid && $only_veid != $veid;
64                    $veid =~ s/^0$/_hw_0/;
65    
66                  my $s = c('VSZ');                  my $s = c('VSZ');
67                  if ( $s < $too_small ) {                  my $cmd = c('COMMAND');
68                    if ( $cmd =~ $filter ) {
69    
70                            $veid .= '-' . $1;
71                            $vsz->{$t}->{$veid} += $s * 1024;
72                            print STDERR uc(substr($1,0,1));
73    
74                    } elsif ( $s < $too_small ) {
75    
76                          $vsz->{$t}->{$veid}+= $s * 1024;                          $vsz->{$t}->{$veid}+= $s * 1024;
77                          print STDERR ".";                          print STDERR ".";
78    
79                  } else {                  } else {
80                          my $cmd = c('COMMAND');  
81                          $cmd =~ s{-.+$}{};                          $cmd =~ s{-.+$}{};
82                          $cmd =~ s{^/\S+/(\w+?)}{$1};                          $cmd =~ s{^/\S+/(\w+?)}{$1};
83                          $cmd =~ s{^\w+ /\S+/(\w+?)}{$1};                          $cmd =~ s{^\w+ /\S+/(\w+?)}{$1};
# Line 70  sub count { Line 93  sub count {
93    
94  }  }
95    
96  print STDERR "reading ps dumps";  print STDERR "parsing ps with grouping < $too_small k";
97    
98  count $_ foreach @ARGV;  count $_ foreach @ARGV;
99    
100  #print "VSZ: ",dump( $vsz );  #print "VSZ: ",dump( $vsz );
101    
102  my @veids = keys %$veids;  my @veids = sort keys %$veids;
103  warn "# veids = ",dump( sort @veids );  warn "# veids = ",dump( @veids );
104    
105  my $rrd_file = 'ps.rrd';  my $rrd_file = 'ps.rrd';
106  unlink $rrd_file if -e $rrd_file;  unlink $rrd_file if -e $rrd_file;
107    
108    my @t = sort keys %$vsz;
109    
110    print "\ndrawing $#t intervals ", $t[0], " - ", $t[$#t];
111    
112  my $rrd = RRD::Simple->new( file => $rrd_file );  my $rrd = RRD::Simple->new( file => $rrd_file );
113  $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );  $rrd->create( map { ( $_ => 'GAUGE' ) } @veids );
114    
115  foreach my $t ( sort keys %$vsz ) {  foreach my $t ( @t ) {
116          print STDERR ".";          print STDERR ".";
117  #       warn "## ",dump( %{ $vsz->{$t} } );  #       warn "## ",dump( %{ $vsz->{$t} } );
118    

Legend:
Removed from v.10  
changed lines
  Added in v.14

  ViewVC Help
Powered by ViewVC 1.1.26