/[cricket]/create_vmstat_Default.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 /create_vmstat_Default.pl

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

revision 1.1 by dpavlin, Tue Oct 28 15:18:20 2003 UTC revision 1.2 by dpavlin, Tue Oct 28 16:00:35 2003 UTC
# Line 12  Line 12 
12  use strict;  use strict;
13  use Data::Dumper;  use Data::Dumper;
14    
15  # define temp cache file -- this is (mybe) security risk! This file name  # variant (-s for vmstat -s)
16  # is easily guessable and it's called via cat from cricket  my $is_s = shift @ARGV;
 my $cache = '/tmp/vmstat-\%auto-target-name\%';  
   
17    
18    my $target_type = "vmstat";
19    $target_type = "vmstat-stat" if ($is_s);
20    
21  my $target = qq(  my $target_def_fmt = qq(
22  Target  --default--  Target  --default--
23          directory-desc  = "Report virtual memory statistics"          directory-desc  = "Report virtual memory statistics"
24          short-desc      =       "Virtual memory"          short-desc      =       "Virtual memory"
25    
26          target-type     =       vmstat          target-type     =       %s
27    
28          # by default don't use ssh          # by default don't use ssh
29          ssh=""          ssh=""
# Line 72  target %s Line 72  target %s
72  # definition for VM mode (copy/paster from vmstat man page :-)  # definition for VM mode (copy/paster from vmstat man page :-)
73    
74  my $ds_type = {  my $ds_type = {
75            # vmstat
76          'si' => 'ABSOLUTE',          'si' => 'ABSOLUTE',
77          'so' => 'ABSOLUTE',          'so' => 'ABSOLUTE',
78          'bi' => 'ABSOLUTE',          'bi' => 'ABSOLUTE',
# Line 110  my $definition = qq( Line 111  my $definition = qq(
111         wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.         wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.
112  );  );
113    
114    # definition for vmstat -s created using vmstat -s -S K | cut -c15-
115    # with editing for units (encosed in [])
116    $definition = qq(
117    Memory
118    tm: [kB] total memory
119    um: [kB] used memory
120    am: [kB] active memory
121    im: [kB] inactive memory
122    fm: [kB] free memory
123    bm: [kB] buffer memory
124    sc: [kB] swap cache
125    ts: [kB] total swap
126    us: [kB] used swap
127    fs: [kB] free swap
128    Ticks
129    nnct: non-nice user cpu ticks   [ticks]
130    nct: nice user cpu ticks        [ticks]
131    sct: system cpu ticks           [ticks]
132    ict: idle cpu ticks             [ticks]
133    ioct: IO-wait cpu ticks         [ticks]
134    Pages
135    ppi: pages paged in             [pages]
136    ppo: pages paged out            [pages]
137    psi: pages swapped in   [pages]
138    pso: pages swapped out  [pages]
139    Other
140    int: interrupts
141    ccs: CPU context switches
142    bt: boot time
143    fork: forks
144    ) if ($is_s);
145    
146  my @ds;  my @ds;
147  my @views;  my @views;
148  my $view_ds;  my $view_ds;
149    my $ds_unit;
150  my $desc;  my $desc;
151    
152  # start parsing at which element  # start parsing at which element
# Line 126  foreach (split(/[\n\r]+/,$definition)) { Line 160  foreach (split(/[\n\r]+/,$definition)) {
160                  # view definition                  # view definition
161                  $curr_view = $1;                  $curr_view = $1;
162                  push @views, $curr_view;                  push @views, $curr_view;
163          } elsif (/^\s+(\w+):\s+(.+)$/) {          } elsif (/^\s*(\w+):\s+(.+)$/) {
164                  # source name: description                  # source name: description
165                  my ($ds,$description) = ($1,$2);                  my ($ds,$description) = ($1,$2);
166                  $ds_max++;                  $ds_max++;
167                  push @ds,$ds;                  push @ds,$ds;
168                  push @{$view_ds->{$curr_view}},$ds;                  push @{$view_ds->{$curr_view}},$ds;
169                    if ($description =~ s/\s*\[([^\]]+)\]\s*//) {
170                            $ds_unit->{$ds} = $1;
171                    }
172                  $desc->{$ds} = $description;                  $desc->{$ds} = $description;
173          } else {          } else {
174                  print STDERR "unparsable line: $_\n";                  print STDERR "unparsable line: $_\n";
175          }          }
176  }  }
177    
 # variant (-s for vmstat -s)  
 my $is_s = 0;  
   
 my $ssh = shift @ARGV;  
 if ($ssh && $ssh eq "-s") {  
         $ssh = shift @ARGV;  
         $is_s = 1;  
 }  
   
178  # don't use value 0 it's empty!  # don't use value 0 it's empty!
179  my $vmstat = qq(\%ssh\% vmstat 1 2 | tail -1 | sed 's/  */\\\\n/'g | tee $cache);  my $vmstat = qq(\%ssh\% vmstat 1 2 | tail -1 | sed 's/  */\\\\n/'g);
180  my $ds_start = 1;  my $ds_start = 1;
181    
182  #my $vmstats = qq(vmstat -s -S K);  if ($is_s) {
183            $vmstat = qq(\%ssh\% vmstat -s -S K);
184            $ds_start = 0;
185    }
186    
187    
188  # dump Target  # dump Target
189  print $target;  printf($target_def_fmt,$target_type);
190    
191    
192  # dump targetType  # dump targetType
# Line 164  foreach (keys %{$view_ds}) { Line 195  foreach (keys %{$view_ds}) {
195          $view_str .= "$_: ".join(" ",@{$view_ds->{$_}}).", ";          $view_str .= "$_: ".join(" ",@{$view_ds->{$_}}).", ";
196  }  }
197  $view_str =~ s/, $//;  $view_str =~ s/, $//;
198  printf($targetType_fmt, 'vmstat', join(", ",@ds), $view_str);  printf($targetType_fmt, $target_type, join(", ",@ds), $view_str);
199    
200    
201  # dump dataSource  # dump dataSource
# Line 193  foreach my $ds (@ds) { Line 224  foreach my $ds (@ds) {
224    
225  # dump graph(s)  # dump graph(s)
226  foreach my $ds (@ds) {  foreach my $ds (@ds) {
227          printf($graph_fmt, $ds, 'LINE3', $desc->{$ds}, $ds);          printf($graph_fmt, $ds, 'LINE3', $desc->{$ds}, $ds_unit->{$ds} || "");
228  }  }
229    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.26