VBTK/DBI/OraTableSpace.pm untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 98 CC 3 SCAR 16.1
CC
3
Cov
0%
addVBObj
12.0
new
2.0
BEGIN
2.0
CRAP 5.0
1 #############################################################################
2 #
3 # NOTE: This file under revision control using RCS
4 # Any changes made without RCS will be lost
5 #
6 # $Source: /usr/local/cvsroot/vbtk/VBTK/DBI/OraTableSpace.pm,v $
7 # $Revision: 1.9 $
8 # $Date: 2002/03/04 20:53:07 $
9 # $Author: bhenry $
10 # $Locker: $
11 # $State: Exp $
12 #
13 # Purpose: An extension of VBTK::DBI for use in monitoring free
14 # space in oracle tablespaces.
15 #
16 # Depends on: VBTK::Common, VBTK::DBI
17 #
18 # Copyright (C) 1996 - 2002 Brent Henry
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of version 2 of the GNU General Public
22 # License as published by the Free Software Foundation available at:
23 # http://www.gnu.org/copyleft/gpl.html
24 #
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
29 #
30 #############################################################################
31 #
32 #
33 # REVISION HISTORY:
34 #
35 # $Log: OraTableSpace.pm,v $
36 # Revision 1.9 2002/03/04 20:53:07 bhenry
37 # *** empty log message ***
38 #
39 # Revision 1.8 2002/03/04 16:49:10 bhenry
40 # Changed requirement back to perl 5.6.0
41 #
42 # Revision 1.7 2002/03/02 00:53:55 bhenry
43 # Documentation updates
44 #
45 # Revision 1.6 2002/02/13 07:36:27 bhenry
46 # Disabled RrdLogRecovery and removed use of @log
47 #
48 #
49  
50 package VBTK::DBI::OraTableSpace;
51  
52 use 5.6.0;
53 use strict;
54 use warnings;
55 # I like using undef as a value so I'm turning off the uninitialized warnings
56 no warnings qw(uninitialized);
57  
58 use VBTK::Common;
59 use VBTK::DBI;
60  
61 # Inherit methods from VBTK::DBI;
62 our @ISA=qw(VBTK::DBI);
63  
64 our $VERBOSE = $ENV{VERBOSE};
65  
66 #-------------------------------------------------------------------------------
67 # Function: new
68 # Description: Object constructor. Allocates memory for all class members
69 # Input Parms:
70 # Output Parms: Pointer to class
71 #-------------------------------------------------------------------------------
72 sub new
73 {
74 my $type = shift;
75 my $self = {};
76 bless $self, $type;
77  
78 # Store all passed input name pairs in the object
79 $self->set(@_);
80  
81 my $stdHeader = [
82 'time tablespace tot_mb free_mb used max_ext',
83 '------------------ --------------------- ------- ------- ---- -------' ];
84  
85 my $stdDetail = [
86 '@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<< @>>>>>> @>>>>>> @>>% @>>>>>>',
87 '$time,$data[0],int($data[1]),int($data[2]),int($data[3]),int($data[4])' ];
88  
89 my $sql = q(
90 select DT_TS_NAME,
91 Sum_Alloc_Blocks * DB_BLOCK_FACTOR,
92 Sum_Free_Blocks * DB_BLOCK_FACTOR,
93 100-(100*Sum_Free_Blocks/Sum_Alloc_Blocks) AS PCT_USED,
94 Max_Blocks * DB_BLOCK_FACTOR
95 from
96 (select Tablespace_Name DT_TS_NAME,
97 SUM(Blocks) Sum_Alloc_Blocks
98 from DBA_DATA_FILES
99 group by Tablespace_Name),
100 (select Tablespace_Name FS_TS_NAME,
101 MAX(Blocks) AS Max_Blocks,
102 SUM(Blocks) AS Sum_Free_Blocks
103 from DBA_FREE_SPACE
104 group by Tablespace_Name),
105 (select (value / 1024 / 1024) DB_BLOCK_FACTOR
106 from v$parameter
107 where name = 'db_block_size')
108 where DT_TS_NAME = FS_TS_NAME
109 order by PCT_USED DESC );
110  
111 # Setup a hash of default parameters
112 my $defaultParms = {
113 Interval => 120,
114 DSN => undef,
115 User => undef,
116 Auth => undef,
117 Attr => 'Oracle',
118 VBHeader => $stdHeader,
119 VBDetail => $stdDetail,
120 VBServerURI => $::VBURI,
121 PreProcessor => undef,
122 LogFile => undef,
123 LogHeader => undef,
124 LogDetail => $stdDetail,
125 RotateLogAt => undef,
126 SqlClause => $sql
127 };
128  
129 # Run the validation, setting defaults if values are not already set
130 $self->validateParms($defaultParms) || &fatal("Exiting");
131  
132 # Initialize a new DBI object
133 $self->SUPER::new() || return undef
134  
135 # Store the default parms
136 $self->{defaultParms} = $defaultParms;
137  
138 ($self);
139 }
140  
141 #-------------------------------------------------------------------------------
142 # Function: addVBObj
143 # Description: Add a vb object to the DBI object.
144 # Input Parms:
145 # Output Parms: None
146 #-------------------------------------------------------------------------------
147 sub addVBObj
148 {
149 my $self = shift;
150 my $DSN = $self->{DSN};
151 my $User = $self->{User};
152 my $Interval = $self->{Interval};
153 my %args = @_;
154  
155 # Setup some reasonable thresholds
156 my $expireAfterSec = int($Interval * 3);
157 my $description = qq(
158 This object monitors the tablespaces of '$DSN'.
159 );
160  
161 # Remove any '.' characters from the DNS and User names, so that we don't
162 # confuse the VBObject name.
163 $DSN =~ s/\./-/g;
164 $User =~ s/\./-/g;
165  
166 # Setup a hash of rules to be returned
167 my $defaultRules = {
168 VBObjName => ".$::HOST.db.$User\@$DSN.dbspace",
169 TextHistoryLimit => 50,
170 ReverseText => 1,
171 Rules => undef,
172 Requirements => undef,
173 StatusHistoryLimit => 30,
174 StatusChangeActions => undef,
175 StatusUpgradeRules => undef,
176 ExpireAfter => "$expireAfterSec seconds",
177 Description => $description,
178 RrdTimeCol => undef,
179 RrdColumns => [ 'int($data[3])' ],
180 RrdFilter => undef,
181 RrdMin => undef,
182 RrdMax => undef,
183 RrdXFF => undef,
184 RrdCF => 'MAX',
185 RrdDST => undef,
186 };
187  
188 # Run the validation
189 &validateParms(\%args,$defaultRules) || &fatal("Exiting");
190  
191 my ($row,$fsMount,$objName,@data,$result,$vbObj);
192  
193 # Clone the wrapper object and run the clone once so we can get a look at the
194 # output.
195 my $clone = $self->dclone;
196 &VBTK::runAll($clone,0);
197 my $lastRows = $clone->getLastRows;
198  
199 # Make sure we got some data back
200 if (@{$lastRows} < 1)
201 {
202 &error("Can't setup objects for VBTK::DBI::OraTableSpace, because no data " .
203 "was returned from SQL");
204 return undef;
205 }
206  
207 # Store the base objectname so we can add to it
208 my $baseObjName = $args{VBObjName};
209  
210 my(@dataSourceList,$labels,$tablespace,$warnPct,$failPct);
211 my(@labels);
212  
213 # Create one VB object for each filesystem
214 foreach $row (@{$lastRows})
215 {
216 # Get the mount point
217 $tablespace = $row->[0];
218  
219 # Setup warn and fail thresholds based on the type of tablespace
220 ($warnPct,$failPct) = ($tablespace =~ /TEMP/) ? (30,40) : (90,95);
221  
222 # Override parms which vary between objects
223 $args{VBObjName} = "$baseObjName.$tablespace";
224 $args{Filter} = $args{RrdFilter} = "\$data[0] eq '$tablespace'";
225 $args{Rules} = {
226 "(\$data[3] > $warnPct)" => 'Warn',
227 "(\$data[3] > $failPct)" => 'Fail' };
228  
229 # Add the rule
230 $vbObj = $self->SUPER::addVBObj(%args);
231  
232 # Create one graph group which shows only this tablespace.
233 $vbObj->addGraphGroup (
234 GroupNumber => 1,
235 DataSourceList => undef,
236 Labels => 'pct-full',
237 Title => "Tablespace Utilization for $DSN.$tablespace",
238 CF => 'MAX'
239 );
240  
241 # Save some values to be used in graphGroup 2
242 push(@dataSourceList,"$baseObjName.$tablespace:0");
243 push(@labels,"$tablespace");
244 }
245  
246 # Create a second graph group which shows all tablespaces together.
247 $self->addGraphGroup (
248 GroupNumber => 2,
249 DataSourceList => join(',',@dataSourceList),
250 Labels => join(',',@labels),
251 Title => "Tablespace Utilization for $DSN",
252 CF => 'MAX'
253 );
254  
255 (undef);
256 }
257  
258 1;
259 __END__