/[Frey]/trunk/lib/Frey/Shell/sar.pm
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 /trunk/lib/Frey/Shell/sar.pm

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

revision 870 by dpavlin, Tue Dec 16 22:35:05 2008 UTC revision 871 by dpavlin, Wed Dec 17 17:59:59 2008 UTC
# Line 15  has sar_command => ( Line 15  has sar_command => (
15  sub as_sponge {  sub as_sponge {
16          my ($self,$opts) = @_;          my ($self,$opts) = @_;
17    
18          $opts ||= '-u';          $opts ||= $self->sar_command !~ m{-\w} ? '-u' : '';
19    
20          my @rows;          my @rows;
21          my @name;          my @name;
22    
23            my @pos;
24    
25          my $cmd = $self->sar_command . ' ' . $opts;          my $cmd = $self->sar_command . ' ' . $opts;
26          warn "# cmd: $cmd";          warn "# cmd: $cmd";
27    
# Line 28  sub as_sponge { Line 30  sub as_sponge {
30          open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!";          open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!";
31          while(<$fh>) {          while(<$fh>) {
32                  chomp;                  chomp;
33    
34                  if ( m{(\d\d)/(\d\d)/(\d\d\d\d)$} ) {                  if ( m{(\d\d)/(\d\d)/(\d\d\d\d)$} ) {
35                          $date = "$3-$1-$2T";                          $date = "$3-$1-$2T";
36                          warn "# date $date";                          warn "# date $date";
37                            next;
38                  }                  }
39    
40                  next unless m{^\d\d:\d\d:\d\d};                  next unless m{^\d\d:\d\d:\d\d};
41                  my @l = split(/\s+/,$_);  
42                  if ( $l[$#l] =~ m{_([^_]+)_} ) {                  my @l;
43                          warn "# header $1 ",join('|', @l);  
44                          $l[0] =~ s{00:00:01}{time} || die "can't locate time column in header";                  if ( s{_([^_]+)_$}{} ) {
45                          delete( $l[$#l] );                          my $line = $_;
46                            warn "# header $1 from $line";
47                            while ( $line =~ s{^(\s*\S+)}{} ) {
48                                    push @pos, length($1);
49                            }
50                            warn "# pos: ", $self->dump( @pos );
51                            my @l = split(/\s+/,$_);
52                            warn "# l: ", $self->dump( @l );
53                            $l[0] =~ s{00:00:0\d}{time} || die "can't locate time column in header";
54                          @name = @l;                          @name = @l;
55                          next;                          next;
56                    } elsif ( @pos ) {
57                            my @cols = split(/\s+/,$_);
58                            if ( $#cols < $#name ) {
59                                    warn "# skip too short line: '$_'";
60                                    next;
61                            }
62                            my $start = 0;
63                            foreach my $len ( @pos ) {
64                                    my $v = substr($_, $start, $len);
65                                    $v =~ s/^\s+//g;
66                                    push @l, $v;
67                                    $start += $len;
68                            }
69                    } else {
70                            die "got: $_ before header!";
71                  }                  }
72    
73                  $l[0] = $date . $l[0];                  $l[0] = $date . $l[0];

Legend:
Removed from v.870  
changed lines
  Added in v.871

  ViewVC Help
Powered by ViewVC 1.1.26