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

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

revision 903 by dpavlin, Thu Dec 25 18:05:07 2008 UTC revision 926 by dpavlin, Mon Jan 5 22:10:59 2009 UTC
# Line 6  with 'Frey::Web'; Line 6  with 'Frey::Web';
6  #with 'Frey::Storage';  #with 'Frey::Storage';
7  with 'Frey::jQuery';  with 'Frey::jQuery';
8  with 'Frey::File'; # FIXME inline on demand?  with 'Frey::File'; # FIXME inline on demand?
9    with 'Frey::Web::IFrame';
10    
11  use DateTimeX::Easy;  use DateTimeX::Easy;
12    
13  use lib 'lib';  use lib 'lib';
 use Frey::Shell::sar;  
14  use JSON;  use JSON;
15    
16  has sar_command => (  has 'sponge' => (
17          is => 'rw',          is => 'rw',
18          isa => 'Str',          isa => 'Sponge',
19          required => 1,          required => 1,
         default => 'ssh www.rot13.org sar -n 1',  
20  );  );
21    
22  sub as_markup {  sub as_markup {
# Line 30  sub as_markup { Line 29  sub as_markup {
29                  <script language="javascript" type="text/javascript" src="/$path/jquery.flot.js"></script>                  <script language="javascript" type="text/javascript" src="/$path/jquery.flot.js"></script>
30          |);          |);
31    
32          my $sponge = Frey::Shell::sar->new( sar_command => $self->sar_command )->as_sponge;          my $sponge = $self->sponge;
         #warn $self->dump( $sponge );  
33    
34          my $by_col;          my $by_col;
35          my $unit_by_col;          my $unit_by_col;
36    
37          foreach my $row ( @{ $sponge->{rows} } ) {          foreach my $row ( @{ $sponge->{rows} } ) {
38                  my $x = DateTimeX::Easy->new( $row->[0] )->epoch * 1000; # ms                  my $time = eval {
39                            DateTimeX::Easy->new( $row->[0] )->epoch * 1000; # ms
40                    };
41                    die "FATAL: sponge first column ", $self->dump( $row->[0] ), " isn't valid time because of: $@" if $@;
42                  foreach my $col ( 1 .. $#$row ) {                  foreach my $col ( 1 .. $#$row ) {
43                          my $v = $row->[$col];                          my $v = $row->[$col];
44                          $unit_by_col->{$col} = $1 if $v =~ s{([M%])$}{};                          $unit_by_col->{$col} = $1 if $v =~ s{([M%])$}{};
45                          push @{ $by_col->{$col} }, [ $x, $v ];                          push @{ $by_col->{$col} }, [ $time, $v ];
46                  }                  }
47          }          }
48    
# Line 63  sub as_markup { Line 64  sub as_markup {
64                  $placeholder = qq|                  $placeholder = qq|
65                          <div id="placeholder" style="width:600px;height:300px;"></div>                          <div id="placeholder" style="width:600px;height:300px;"></div>
66                          <div id="selection">no selection</div>                          <div id="selection">no selection</div>
67                  |;                  |
68                    . $self->iframe_html
69                    ;
70          }          }
71    
72          warn "# $data_js" if $self->debug;          warn "# $data_js" if $self->debug;
73    
74          my $sar = $self->sar_command;          my $form = '<!-- no sar_command in sponge -->';
75          my $c = $sar;          my $sar_command = $sponge->{sar_command} || warn "no sar_command in spunge";
76          $c =~ s{sar\s(-n\s*\d+)?(.*?)$}{sar $1};          if ( my $c = $sar_command ) {
77                    $c =~ s{sar\s(-n\s*\d+)?(.*?)$}{sar $1};
78          my $form = qq|  
79                  <form method="post">                  $form = qq|
80                  <b>From</b> <input type="submit" value="refresh"><br>                          <form method="post">
81          |;                          <b>From</b> <input type="submit" value="refresh"><br>
82                    |;
83          my $flags = `atsar help 2>&1`;  
84          $flags =~ s{^.+flags:\s+}{}s;                  my $flags = `atsar help 2>&1`;
85          $flags =~ s{^\s*-[AS].+$}{}gm; # remove -A and -S flags which doesn't make sense                  $flags =~ s{^.+flags:\s+}{}s;
86          $flags =~ s{^\s+}{}s;                  $flags =~ s{^\s*-[AS].+$}{}gm; # remove -A and -S flags which doesn't make sense
87                    $flags =~ s{^\s+}{}s;
88          foreach my $line ( split(/\s*\n\s*/, $flags ) ) {  
89                  my ( $flag, $desc ) = split(/\s+/, $line, 2 );                  foreach my $line ( split(/\s*\n\s*/, $flags ) ) {
90                  warn "# $flag | $desc";                          my ( $flag, $desc ) = split(/\s+/, $line, 2 );
91                  my $v = "$c $flag";                          warn "# $flag | $desc" if $self->debug;
92                  my $checked = '';                          my $v = "$c $flag";
93                  $checked = " checked" if $self->sar_command =~ m{$flag};                          my $checked = '';
94                  $form .= qq|<input type="radio" name="sar_command" value="$v"$checked>$desc<br>\n|;                          $checked = " checked" if $sar_command =~ m{$flag};
95          }                          $form .= qq|<input type="radio" name="sar_command" value="$v"$checked>$desc<br>\n|;
96                    }
97    
98          $form .= qq|                  $form .= qq|
99                  </form>                          </form>
100          |;                  |;
101    
102          $self->add_css(q|                  $self->add_css(q|
103                  #choices, form { float: left; }                          #choices, form { float: left; }
104          |);                  |);
105            }
106    
107          return          return
108          qq|          qq|
109    
110                  <code>$sar</code>                  <code>$sar_command</code>
111    
112                  $placeholder                  $placeholder
113    

Legend:
Removed from v.903  
changed lines
  Added in v.926

  ViewVC Help
Powered by ViewVC 1.1.26