Parent Directory | Revision Log
simple integration of sar command to produce tabular output (sponge)
1 | package Frey::Shell::sar; |
2 | use Moose; |
3 | |
4 | extends 'Frey'; |
5 | with 'Frey::Web'; |
6 | #with 'Frey::Storage'; |
7 | |
8 | has sar_command => ( |
9 | is => 'rw', |
10 | isa => 'Str', |
11 | required => 1, |
12 | default => 'sar', |
13 | ); |
14 | |
15 | sub as_sponge { |
16 | my ($self,$opts) = @_; |
17 | |
18 | $opts ||= '-u'; |
19 | |
20 | my @rows; |
21 | my @name; |
22 | |
23 | my $cmd = $self->sar_command . ' ' . $opts; |
24 | warn "# cmd: $cmd"; |
25 | |
26 | open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!"; |
27 | while(<$fh>) { |
28 | chomp; |
29 | next unless m{^\d\d:\d\d:\d\d}; |
30 | my @l = split(/\s+/,$_); |
31 | if ( $l[$#l] =~ m{_([^_]+)_} ) { |
32 | warn "# header $1 ",join('|', @l); |
33 | $l[0] =~ s{00:00:01}{time} || die "can't locate time column in header"; |
34 | delete( $l[$#l] ); |
35 | @name = @l; |
36 | next; |
37 | } |
38 | |
39 | push @rows, [ @l ]; |
40 | } |
41 | |
42 | return { |
43 | rows => \@rows, |
44 | NAME => \@name, |
45 | } |
46 | } |
47 | |
48 | 1; |
ViewVC Help | |
Powered by ViewVC 1.1.26 |