/[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.1 - (hide annotations)
Tue Oct 28 15:18:20 2003 UTC (20 years, 5 months ago) by dpavlin
Branch: MAIN
File MIME type: text/plain
script to create Default file for vmstat (optionally using ssh to fetch
values from remote hosts), working draft

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     # define temp cache file -- this is (mybe) security risk! This file name
16     # is easily guessable and it's called via cat from cricket
17     my $cache = '/tmp/vmstat-\%auto-target-name\%';
18    
19    
20    
21     my $target = qq(
22     Target --default--
23     directory-desc = "Report virtual memory statistics"
24     short-desc = "Virtual memory"
25    
26     target-type = vmstat
27    
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     'si' => 'ABSOLUTE',
76     'so' => 'ABSOLUTE',
77     'bi' => 'ABSOLUTE',
78     'bo' => 'ABSOLUTE',
79     };
80    
81     my $definition = qq(
82     Procs
83     r: The number of processes waiting for run time.
84     b: The number of processes in uninterruptible sleep.
85    
86     Memory
87     swpd: the amount of virtual memory used.
88     free: the amount of idle memory.
89     buff: the amount of memory used as buffers.
90     cache: the amount of memory used as cache.
91     # inact: the amount of inactive memory. (-a option)
92     # active: the amount of active memory. (-a option)
93    
94     Swap
95     si: Amount of memory swapped in from disk (/s).
96     so: Amount of memory swapped to disk (/s).
97    
98     IO
99     bi: Blocks received from a block device (blocks/s).
100     bo: Blocks sent to a block device (blocks/s).
101    
102     System
103     in: The number of interrupts per second, including the clock.
104     cs: The number of context switches per second.
105    
106     CPU
107     us: Time spent running non-kernel code. (user time, including nice time)
108     sy: Time spent running kernel code. (system time)
109     id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
110     wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.
111     );
112    
113     my @ds;
114     my @views;
115     my $view_ds;
116     my $desc;
117    
118     # start parsing at which element
119     my $ds_max = 0;
120     my $curr_view = "Default";
121    
122     foreach (split(/[\n\r]+/,$definition)) {
123     chomp;
124     next if (/^$/ || /^#/);
125     if (/^\s*(\w+)\s*$/) {
126     # view definition
127     $curr_view = $1;
128     push @views, $curr_view;
129     } elsif (/^\s+(\w+):\s+(.+)$/) {
130     # source name: description
131     my ($ds,$description) = ($1,$2);
132     $ds_max++;
133     push @ds,$ds;
134     push @{$view_ds->{$curr_view}},$ds;
135     $desc->{$ds} = $description;
136     } else {
137     print STDERR "unparsable line: $_\n";
138     }
139     }
140    
141     # variant (-s for vmstat -s)
142     my $is_s = 0;
143    
144     my $ssh = shift @ARGV;
145     if ($ssh && $ssh eq "-s") {
146     $ssh = shift @ARGV;
147     $is_s = 1;
148     }
149    
150     # don't use value 0 it's empty!
151     my $vmstat = qq(\%ssh\% vmstat 1 2 | tail -1 | sed 's/ */\\\\n/'g | tee $cache);
152     my $ds_start = 1;
153    
154     #my $vmstats = qq(vmstat -s -S K);
155    
156    
157     # dump Target
158     print $target;
159    
160    
161     # dump targetType
162     my $view_str;
163     foreach (keys %{$view_ds}) {
164     $view_str .= "$_: ".join(" ",@{$view_ds->{$_}}).", ";
165     }
166     $view_str =~ s/, $//;
167     printf($targetType_fmt, 'vmstat', join(", ",@ds), $view_str);
168    
169    
170     # dump dataSource
171     my $i=$ds_start; # start ds on line
172     foreach my $ds (@ds) {
173     my $cmd = $vmstat;
174     my $scheme = "exec";
175    
176     #if ($i == $ds_start) {
177     # # first ds dumps vmstat and cache in in tmp file
178     # $cmd = $vmstat;
179     #} elsif ($i == $ds_max) {
180     # # last row should also erase cache
181     # $cmd = "cat $cache && rm $cache";
182     #} else {
183     # # while all other rows just dump cache file
184     # $scheme = "file";
185     # $cmd = $cache;
186     # #$cmd = "cat $cache";
187     #}
188    
189     printf($dataSource_fmt, $ds,$ds_type->{$ds} || 'GAUGE',$scheme,$i,$cmd);
190    
191     $i++;
192     }
193    
194     # dump graph(s)
195     foreach my $ds (@ds) {
196     printf($graph_fmt, $ds, 'LINE3', $desc->{$ds}, $ds);
197     }
198    

  ViewVC Help
Powered by ViewVC 1.1.26