/[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

Annotation of /create_vmstat_Default.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Tue Oct 28 16:00:35 2003 UTC (20 years, 5 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +52 -21 lines
File MIME type: text/plain
added usage of vmstat -s

1 dpavlin 1.1 #!/usr/bin/perl -w
2     #
3     # This script will create Default files for two vmstat veriants
4     #
5     # 2003-10-27 Dobrica Pavlinusic <dpavlin@rot13.org>
6     #
7     # Due to cricket's eagerness to execute first data sources, your data
8     # *WILL BE* delayed by 5 minutes (or one cricket interval) on your
9     # graphs. Reason is that cricket first tries to read file (from last
10     # run) and then executes vmstat which will produce new file.
11    
12     use strict;
13     use Data::Dumper;
14    
15 dpavlin 1.2 # variant (-s for vmstat -s)
16     my $is_s = shift @ARGV;
17 dpavlin 1.1
18 dpavlin 1.2 my $target_type = "vmstat";
19     $target_type = "vmstat-stat" if ($is_s);
20 dpavlin 1.1
21 dpavlin 1.2 my $target_def_fmt = qq(
22 dpavlin 1.1 Target --default--
23     directory-desc = "Report virtual memory statistics"
24     short-desc = "Virtual memory"
25    
26 dpavlin 1.2 target-type = %s
27 dpavlin 1.1
28     # by default don't use ssh
29     ssh=""
30    
31     # comment following line if you don't want alerts for filespace
32     # to be created in /var/log/cricket/alters
33     # change n to number for low mark and 90 to high mark
34     #monitor-thresholds = "df : value : n : 90 : FILE : /var/log/cricket/alerts"
35     );
36    
37     my $dataSource_fmt = qq(
38     dataSource %s
39     rrd-ds-type = %s
40     rrd-heartbeat = 1800
41     ds-source = "%s:%s:%s"
42     # rrd-min = 0
43     # rrd-max = undef
44     precision = integer
45     ); # name, type=GAUGE|DERIVE, 0-x, script
46    
47     my $graph_fmt = qq(
48     graph %s
49     draw-as = %s
50     legend = "%s"
51     units = "%s"
52     ); # name, AREA|LINE3, legend, y-axis, units
53    
54    
55     my $targetType_fmt = qq(
56     targetType %s
57     ds = "%s"
58     view = "%s"
59     # y-min = 0
60     # y-max = 100
61    
62     graph --default--
63     height = 278
64     height-hint = 278
65     ); # name, ds (separated by spaces), view (Name: ds ds[,..])
66    
67     my $target_fmt = qq(
68     target %s
69     ssh = %s
70     );
71    
72     # definition for VM mode (copy/paster from vmstat man page :-)
73    
74     my $ds_type = {
75 dpavlin 1.2 # vmstat
76 dpavlin 1.1 'si' => 'ABSOLUTE',
77     'so' => 'ABSOLUTE',
78     'bi' => 'ABSOLUTE',
79     'bo' => 'ABSOLUTE',
80     };
81    
82     my $definition = qq(
83     Procs
84     r: The number of processes waiting for run time.
85     b: The number of processes in uninterruptible sleep.
86    
87     Memory
88     swpd: the amount of virtual memory used.
89     free: the amount of idle memory.
90     buff: the amount of memory used as buffers.
91     cache: the amount of memory used as cache.
92     # inact: the amount of inactive memory. (-a option)
93     # active: the amount of active memory. (-a option)
94    
95     Swap
96     si: Amount of memory swapped in from disk (/s).
97     so: Amount of memory swapped to disk (/s).
98    
99     IO
100     bi: Blocks received from a block device (blocks/s).
101     bo: Blocks sent to a block device (blocks/s).
102    
103     System
104     in: The number of interrupts per second, including the clock.
105     cs: The number of context switches per second.
106    
107     CPU
108     us: Time spent running non-kernel code. (user time, including nice time)
109     sy: Time spent running kernel code. (system time)
110     id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
111     wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.
112     );
113    
114 dpavlin 1.2 # 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 dpavlin 1.1 my @ds;
147     my @views;
148     my $view_ds;
149 dpavlin 1.2 my $ds_unit;
150 dpavlin 1.1 my $desc;
151    
152     # start parsing at which element
153     my $ds_max = 0;
154     my $curr_view = "Default";
155    
156     foreach (split(/[\n\r]+/,$definition)) {
157     chomp;
158     next if (/^$/ || /^#/);
159     if (/^\s*(\w+)\s*$/) {
160     # view definition
161     $curr_view = $1;
162     push @views, $curr_view;
163 dpavlin 1.2 } elsif (/^\s*(\w+):\s+(.+)$/) {
164 dpavlin 1.1 # source name: description
165     my ($ds,$description) = ($1,$2);
166     $ds_max++;
167     push @ds,$ds;
168     push @{$view_ds->{$curr_view}},$ds;
169 dpavlin 1.2 if ($description =~ s/\s*\[([^\]]+)\]\s*//) {
170     $ds_unit->{$ds} = $1;
171     }
172 dpavlin 1.1 $desc->{$ds} = $description;
173     } else {
174     print STDERR "unparsable line: $_\n";
175     }
176     }
177    
178     # don't use value 0 it's empty!
179 dpavlin 1.2 my $vmstat = qq(\%ssh\% vmstat 1 2 | tail -1 | sed 's/ */\\\\n/'g);
180 dpavlin 1.1 my $ds_start = 1;
181    
182 dpavlin 1.2 if ($is_s) {
183     $vmstat = qq(\%ssh\% vmstat -s -S K);
184     $ds_start = 0;
185     }
186 dpavlin 1.1
187    
188     # dump Target
189 dpavlin 1.2 printf($target_def_fmt,$target_type);
190 dpavlin 1.1
191    
192     # dump targetType
193     my $view_str;
194     foreach (keys %{$view_ds}) {
195     $view_str .= "$_: ".join(" ",@{$view_ds->{$_}}).", ";
196     }
197     $view_str =~ s/, $//;
198 dpavlin 1.2 printf($targetType_fmt, $target_type, join(", ",@ds), $view_str);
199 dpavlin 1.1
200    
201     # dump dataSource
202     my $i=$ds_start; # start ds on line
203     foreach my $ds (@ds) {
204     my $cmd = $vmstat;
205     my $scheme = "exec";
206    
207     #if ($i == $ds_start) {
208     # # first ds dumps vmstat and cache in in tmp file
209     # $cmd = $vmstat;
210     #} elsif ($i == $ds_max) {
211     # # last row should also erase cache
212     # $cmd = "cat $cache && rm $cache";
213     #} else {
214     # # while all other rows just dump cache file
215     # $scheme = "file";
216     # $cmd = $cache;
217     # #$cmd = "cat $cache";
218     #}
219    
220     printf($dataSource_fmt, $ds,$ds_type->{$ds} || 'GAUGE',$scheme,$i,$cmd);
221    
222     $i++;
223     }
224    
225     # dump graph(s)
226     foreach my $ds (@ds) {
227 dpavlin 1.2 printf($graph_fmt, $ds, 'LINE3', $desc->{$ds}, $ds_unit->{$ds} || "");
228 dpavlin 1.1 }
229    

  ViewVC Help
Powered by ViewVC 1.1.26