/[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.4 by dpavlin, Mon Nov 3 10:29:05 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',
79          'bo' => 'ABSOLUTE',          'bo' => 'ABSOLUTE',
80            # vmstat -s
81            'nnct' => 'COUNTER',
82            'nct' => 'COUNTER',
83            'sct' => 'COUNTER',
84            'ict' => 'COUNTER',
85            'ioct' => 'COUNTER',
86            'ppi' => 'COUNTER',
87            'ppo' => 'COUNTER',
88            'psi' => 'COUNTER',
89            'pso' => 'COUNTER',
90            'int' => 'COUNTER',
91            'ccs' => 'COUNTER',
92            'bt' => 'COUNTER',
93            'fork' => 'COUNTER',
94  };  };
95    
96  my $definition = qq(  my $definition = qq(
# Line 92  my $definition = qq( Line 107  my $definition = qq(
107  #       active: the amount of active memory. (-a option)  #       active: the amount of active memory. (-a option)
108    
109     Swap     Swap
110         si: Amount of memory swapped in from disk (/s).         si: Amount of memory swapped in from disk [amount/s].
111         so: Amount of memory swapped to disk (/s).         so: Amount of memory swapped to disk [amount/s].
112    
113     IO     IO
114         bi: Blocks received from a block device (blocks/s).         bi: Blocks received from a block device [blocks/s].
115         bo: Blocks sent to a block device (blocks/s).         bo: Blocks sent to a block device [blocks/s].
116    
117     System     System
118         in: The number of interrupts per second, including the clock.         in: The number of interrupts per second, including the clock.
# Line 110  my $definition = qq( Line 125  my $definition = qq(
125         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.
126  );  );
127    
128    # definition for vmstat -s created using vmstat -s -S K | cut -c15-
129    # with editing for units (encosed in [])
130    $definition = qq(
131    Memory
132    tm: [kB] total memory
133    um: [kB] used memory
134    am: [kB] active memory
135    im: [kB] inactive memory
136    fm: [kB] free memory
137    bm: [kB] buffer memory
138    Swap
139    sc: [kB] swap cache
140    ts: [kB] total swap
141    us: [kB] used swap
142    fs: [kB] free swap
143    Ticks
144    nnct: non-nice user cpu ticks   [ticks]
145    nct: nice user cpu ticks        [ticks]
146    sct: system cpu ticks           [ticks]
147    ict: idle cpu ticks             [ticks]
148    ioct: IO-wait cpu ticks         [ticks]
149    Pages
150    ppi: pages paged in             [pages]
151    ppo: pages paged out            [pages]
152    psi: pages swapped in   [pages]
153    pso: pages swapped out  [pages]
154    Interrupts
155    int: interrupts
156    Context_switches
157    ccs: CPU context switches
158    Boot_time
159    bt: boot time
160    Forks
161    fork: forks
162    ) if ($is_s);
163    
164  my @ds;  my @ds;
165  my @views;  my @views;
166  my $view_ds;  my $view_ds;
167    my $ds_unit;
168  my $desc;  my $desc;
169    
170  # start parsing at which element  # start parsing at which element
# Line 126  foreach (split(/[\n\r]+/,$definition)) { Line 178  foreach (split(/[\n\r]+/,$definition)) {
178                  # view definition                  # view definition
179                  $curr_view = $1;                  $curr_view = $1;
180                  push @views, $curr_view;                  push @views, $curr_view;
181          } elsif (/^\s+(\w+):\s+(.+)$/) {          } elsif (/^\s*(\w+):\s+(.+)$/) {
182                  # source name: description                  # source name: description
183                  my ($ds,$description) = ($1,$2);                  my ($ds,$description) = ($1,$2);
184                  $ds_max++;                  $ds_max++;
185                  push @ds,$ds;                  push @ds,$ds;
186                  push @{$view_ds->{$curr_view}},$ds;                  push @{$view_ds->{$curr_view}},$ds;
187                    if ($description =~ s/\s*\[([^\]]+)\]\s*//) {
188                            $ds_unit->{$ds} = $1;
189                    }
190                  $desc->{$ds} = $description;                  $desc->{$ds} = $description;
191          } else {          } else {
192                  print STDERR "unparsable line: $_\n";                  print STDERR "unparsable line: $_\n";
193          }          }
194  }  }
195    
 # variant (-s for vmstat -s)  
 my $is_s = 0;  
   
 my $ssh = shift @ARGV;  
 if ($ssh && $ssh eq "-s") {  
         $ssh = shift @ARGV;  
         $is_s = 1;  
 }  
   
196  # don't use value 0 it's empty!  # don't use value 0 it's empty!
197  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);
198  my $ds_start = 1;  my $ds_start = 1;
199    
200  #my $vmstats = qq(vmstat -s -S K);  if ($is_s) {
201            $vmstat = qq(\%ssh\% vmstat -s -S K);
202            $ds_start = 0;
203    }
204    
205    
206  # dump Target  # dump Target
207  print $target;  printf($target_def_fmt,$target_type);
208    
209    
210  # dump targetType  # dump targetType
# Line 164  foreach (keys %{$view_ds}) { Line 213  foreach (keys %{$view_ds}) {
213          $view_str .= "$_: ".join(" ",@{$view_ds->{$_}}).", ";          $view_str .= "$_: ".join(" ",@{$view_ds->{$_}}).", ";
214  }  }
215  $view_str =~ s/, $//;  $view_str =~ s/, $//;
216  printf($targetType_fmt, 'vmstat', join(", ",@ds), $view_str);  printf($targetType_fmt, $target_type, join(", ",@ds), $view_str);
217    
218    
219  # dump dataSource  # dump dataSource
# Line 193  foreach my $ds (@ds) { Line 242  foreach my $ds (@ds) {
242    
243  # dump graph(s)  # dump graph(s)
244  foreach my $ds (@ds) {  foreach my $ds (@ds) {
245          printf($graph_fmt, $ds, 'LINE3', $desc->{$ds}, $ds);          printf($graph_fmt, $ds, 'LINE3', $desc->{$ds}, $ds_unit->{$ds} || "");
246  }  }
247    

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

  ViewVC Help
Powered by ViewVC 1.1.26