/[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.3 - (hide annotations)
Tue Oct 28 16:45:25 2003 UTC (20 years, 5 months ago) by dpavlin
Branch: MAIN
Changes since 1.2: +19 -4 lines
File MIME type: text/plain
define counters for vmstat -s, more units definition

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 dpavlin 1.3 # 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 dpavlin 1.1 };
95    
96     my $definition = qq(
97     Procs
98     r: The number of processes waiting for run time.
99     b: The number of processes in uninterruptible sleep.
100    
101     Memory
102     swpd: the amount of virtual memory used.
103     free: the amount of idle memory.
104     buff: the amount of memory used as buffers.
105     cache: the amount of memory used as cache.
106     # inact: the amount of inactive memory. (-a option)
107     # active: the amount of active memory. (-a option)
108    
109     Swap
110 dpavlin 1.3 si: Amount of memory swapped in from disk [amount/s].
111     so: Amount of memory swapped to disk [amount/s].
112 dpavlin 1.1
113     IO
114 dpavlin 1.3 bi: Blocks received from a block device [blocks/s].
115     bo: Blocks sent to a block device [blocks/s].
116 dpavlin 1.1
117     System
118     in: The number of interrupts per second, including the clock.
119     cs: The number of context switches per second.
120    
121     CPU
122     us: Time spent running non-kernel code. (user time, including nice time)
123     sy: Time spent running kernel code. (system time)
124     id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
125     wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.
126     );
127    
128 dpavlin 1.2 # 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 dpavlin 1.3 Swap
139 dpavlin 1.2 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     Other
155     int: interrupts
156     ccs: CPU context switches
157     bt: boot time
158     fork: forks
159     ) if ($is_s);
160    
161 dpavlin 1.1 my @ds;
162     my @views;
163     my $view_ds;
164 dpavlin 1.2 my $ds_unit;
165 dpavlin 1.1 my $desc;
166    
167     # start parsing at which element
168     my $ds_max = 0;
169     my $curr_view = "Default";
170    
171     foreach (split(/[\n\r]+/,$definition)) {
172     chomp;
173     next if (/^$/ || /^#/);
174     if (/^\s*(\w+)\s*$/) {
175     # view definition
176     $curr_view = $1;
177     push @views, $curr_view;
178 dpavlin 1.2 } elsif (/^\s*(\w+):\s+(.+)$/) {
179 dpavlin 1.1 # source name: description
180     my ($ds,$description) = ($1,$2);
181     $ds_max++;
182     push @ds,$ds;
183     push @{$view_ds->{$curr_view}},$ds;
184 dpavlin 1.2 if ($description =~ s/\s*\[([^\]]+)\]\s*//) {
185     $ds_unit->{$ds} = $1;
186     }
187 dpavlin 1.1 $desc->{$ds} = $description;
188     } else {
189     print STDERR "unparsable line: $_\n";
190     }
191     }
192    
193     # don't use value 0 it's empty!
194 dpavlin 1.2 my $vmstat = qq(\%ssh\% vmstat 1 2 | tail -1 | sed 's/ */\\\\n/'g);
195 dpavlin 1.1 my $ds_start = 1;
196    
197 dpavlin 1.2 if ($is_s) {
198     $vmstat = qq(\%ssh\% vmstat -s -S K);
199     $ds_start = 0;
200     }
201 dpavlin 1.1
202    
203     # dump Target
204 dpavlin 1.2 printf($target_def_fmt,$target_type);
205 dpavlin 1.1
206    
207     # dump targetType
208     my $view_str;
209     foreach (keys %{$view_ds}) {
210     $view_str .= "$_: ".join(" ",@{$view_ds->{$_}}).", ";
211     }
212     $view_str =~ s/, $//;
213 dpavlin 1.2 printf($targetType_fmt, $target_type, join(", ",@ds), $view_str);
214 dpavlin 1.1
215    
216     # dump dataSource
217     my $i=$ds_start; # start ds on line
218     foreach my $ds (@ds) {
219     my $cmd = $vmstat;
220     my $scheme = "exec";
221    
222     #if ($i == $ds_start) {
223     # # first ds dumps vmstat and cache in in tmp file
224     # $cmd = $vmstat;
225     #} elsif ($i == $ds_max) {
226     # # last row should also erase cache
227     # $cmd = "cat $cache && rm $cache";
228     #} else {
229     # # while all other rows just dump cache file
230     # $scheme = "file";
231     # $cmd = $cache;
232     # #$cmd = "cat $cache";
233     #}
234    
235     printf($dataSource_fmt, $ds,$ds_type->{$ds} || 'GAUGE',$scheme,$i,$cmd);
236    
237     $i++;
238     }
239    
240     # dump graph(s)
241     foreach my $ds (@ds) {
242 dpavlin 1.2 printf($graph_fmt, $ds, 'LINE3', $desc->{$ds}, $ds_unit->{$ds} || "");
243 dpavlin 1.1 }
244    

  ViewVC Help
Powered by ViewVC 1.1.26