| 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/Wrapper/Vmstat.pm,v $ | ||
| 7 | # $Revision: 1.9 $ | ||
| 8 | # $Date: 2002/03/04 20:53:08 $ | ||
| 9 | # $Author: bhenry $ | ||
| 10 | # $Locker: $ | ||
| 11 | # $State: Exp $ | ||
| 12 | # | ||
| 13 | # Purpose: An extension of VBTK::Wrapper for use in running vmstat | ||
| 14 | # | ||
| 15 | # Depends on: VBTK::Common, VBTK::Wrapper | ||
| 16 | # | ||
| 17 | # Copyright (C) 1996 - 2002 Brent Henry | ||
| 18 | # | ||
| 19 | # This program is free software; you can redistribute it and/or | ||
| 20 | # modify it under the terms of version 2 of the GNU General Public | ||
| 21 | # License as published by the Free Software Foundation available at: | ||
| 22 | # http://http://www.gnu.org/copyleft/gpl.html | ||
| 23 | # | ||
| 24 | # This program is distributed in the hope that it will be useful, | ||
| 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 27 | # GNU General Public License for more details. | ||
| 28 | # | ||
| 29 | ############################################################################# | ||
| 30 | # | ||
| 31 | # | ||
| 32 | # REVISION HISTORY: | ||
| 33 | # | ||
| 34 | # $Log: Vmstat.pm,v $ | ||
| 35 | # Revision 1.9 2002/03/04 20:53:08 bhenry | ||
| 36 | # *** empty log message *** | ||
| 37 | # | ||
| 38 | # Revision 1.8 2002/03/04 16:49:10 bhenry | ||
| 39 | # Changed requirement back to perl 5.6.0 | ||
| 40 | # | ||
| 41 | # Revision 1.7 2002/03/02 00:53:56 bhenry | ||
| 42 | # Documentation updates | ||
| 43 | # | ||
| 44 | # Revision 1.6 2002/02/20 20:41:35 bhenry | ||
| 45 | # *** empty log message *** | ||
| 46 | # | ||
| 47 | # Revision 1.5 2002/02/13 07:36:14 bhenry | ||
| 48 | # Disabled RrdLogRecovery and removed use of @log | ||
| 49 | # | ||
| 50 | # Revision 1.4 2002/01/26 06:15:15 bhenry | ||
| 51 | # Changed to not specify absolute path | ||
| 52 | # | ||
| 53 | # Revision 1.3 2002/01/25 07:11:52 bhenry | ||
| 54 | # Changed to inherit from Wrapper | ||
| 55 | # | ||
| 56 | # Revision 1.2 2002/01/21 17:07:56 bhenry | ||
| 57 | # Disabled 'uninitialized' warnings | ||
| 58 | # | ||
| 59 | # Revision 1.1.1.1 2002/01/17 18:05:57 bhenry | ||
| 60 | # VBTK Project | ||
| 61 | # | ||
| 62 | |||
| 63 | package VBTK::Wrapper::Vmstat; | ||
| 64 | |||
| 65 | use 5.6.0; | ||
| 66 | use strict; | ||
| 67 | use warnings; | ||
| 68 | # I like using undef as a value so I'm turning off the uninitialized warnings | ||
| 69 | no warnings qw(uninitialized); | ||
| 70 | |||
| 71 | use VBTK::Common; | ||
| 72 | use VBTK::Wrapper; | ||
| 73 | |||
| 74 | # Inherit methods from VBTK::Wrapper; | ||
| 75 | our @ISA=qw(VBTK::Wrapper); | ||
| 76 | |||
| 77 | our $VERBOSE = $ENV{VERBOSE}; | ||
| 78 | |||
| 79 | #------------------------------------------------------------------------------- | ||
| 80 | # Function: new | ||
| 81 | # Description: Object constructor. Allocates memory for all class members | ||
| 82 | # Input Parms: | ||
| 83 | # Output Parms: Pointer to class | ||
| 84 | #------------------------------------------------------------------------------- | ||
| 85 | sub new | ||
| 86 | { | ||
| 87 | my $type = shift; | ||
| 88 | my $self = {}; | ||
| 89 | bless $self, $type; | ||
| 90 | |||
| 91 | # Store all passed input name pairs in the object | ||
| 92 | $self->set(@_); | ||
| 93 | |||
| 94 | # Setup a default interval | ||
| 95 | my $interval = 60; | ||
| 96 | |||
| 97 | # Setup a standard header and detail line for use in the VBObject and logs. | ||
| 98 | my $stdHeader = | ||
| 99 | [ ' procs memory page disk faults cpu', | ||
| 100 | ' time r b w swap free re mf pi po fr de sr s0 s6 sd sd in sy cs us sy id' ]; | ||
| 101 | my $stdDetail = [ '$time $data' ]; | ||
| 102 | |||
| 103 | # Try to run psrinfo to count the number of CPU's | ||
| 104 | my $numCpus = 1; | ||
| 105 | if (-x "/usr/sbin/psrinfo") | ||
| 106 | { | ||
| 107 | $numCpus = `/usr/sbin/psrinfo | /usr/bin/wc -l`; | ||
| 108 | $numCpus =~ s/\s+//g; | ||
| 109 | } | ||
| 110 | |||
| 111 | # Setup a hash of default parameters | ||
| 112 | my $defaultParms = { | ||
| 113 | Interval => $interval, | ||
| 114 | Execute => "vmstat $interval", | ||
| 115 | SourceList => undef, | ||
| 116 | VBServerURI => $::VBURI, | ||
| 117 | VBHeader => $stdHeader, | ||
| 118 | VBDetail => $stdDetail, | ||
| 119 | LogFile => undef, | ||
| 120 | LogHeader => $stdHeader, | ||
| 121 | LogDetail => $stdDetail, | ||
| 122 | RotateLogAt => '12:00am', | ||
| 123 | RotateLogOnEOF => undef, | ||
| 124 | Split => '\s+', | ||
| 125 | Filter => '^\s*\d+[^a-zA-Z]*$', | ||
| 126 | Ignore => undef, | ||
| 127 | SkipLines => 3, | ||
| 128 | Timeout => undef, | ||
| 129 | TimeoutStatus => undef, | ||
| 130 | Follow => 1, | ||
| 131 | FollowTimeout => ((2 * $interval) + 10), | ||
| 132 | FollowHeartbeat => undef, | ||
| 133 | SetRunStatus => undef, | ||
| 134 | NonZeroExitStatus => undef, | ||
| 135 | SuppressStdout => undef, | ||
| 136 | SuppressMessages => undef, | ||
| 137 | DebugHeader => 'vmstat', | ||
| 138 | NumCpus => $numCpus | ||
| 139 | }; | ||
| 140 | |||
| 141 | # Run the validation, setting defaults if values are not already set | ||
| 142 | $self->validateParms($defaultParms) || &fatal("Exiting"); | ||
| 143 | |||
| 144 | # Temporarily remove parms which we don't want to pass on to the real wrapper. | ||
| 145 | delete $self->{NumCpus}; | ||
| 146 | |||
| 147 | # Initialize a wrapper object. | ||
| 148 | $self->SUPER::new() || return undef; | ||
| 149 | |||
| 150 | # Store the default parms | ||
| 151 | $self->{defaultParms} = $defaultParms; | ||
| 152 | $self->{NumCpus} = $numCpus; | ||
| 153 | |||
| 154 | ($self); | ||
| 155 | } | ||
| 156 | |||
| 157 | #------------------------------------------------------------------------------- | ||
| 158 | # Function: addVBObj | ||
| 159 | # Description: Add a vb object to the wrapper object. | ||
| 160 | # Input Parms: | ||
| 161 | # Output Parms: None | ||
| 162 | #------------------------------------------------------------------------------- | ||
| 163 | sub addVBObj | ||
| 164 | { | ||
| 165 | my $self = shift; | ||
| 166 | my $NumCpus = $self->{NumCpus}; | ||
| 167 | my $Interval = $self->{Interval}; | ||
| 168 | my %args = @_; | ||
| 169 | |||
| 170 | # Setup some reasonable thresholds | ||
| 171 | my $warnRunQueue = $NumCpus; | ||
| 172 | my $failRunQueue = $NumCpus * 4; | ||
| 173 | my $expireAfterSec = int($Interval * 3); | ||
| 174 | my $description = qq( | ||
| 175 | This object uses the 'vmstat' command to monitor the CPU utilization | ||
| 176 | on $::HOST. It will set the status to 'Warning' or 'Failed' based on the | ||
| 177 | value of the run queue and the CPU idle time. | ||
| 178 | ); | ||
| 179 | |||
| 180 | # Setup a hash of rules to be returned | ||
| 181 | my $defaultRules = { | ||
| 182 | VBObjName => ".$::HOST.cpu", | ||
| 183 | TextHistoryLimit => 100, | ||
| 184 | ReverseText => 1, | ||
| 185 | Rules => { | ||
| 186 | "(\$data[1] > $warnRunQueue)" => 'Warn', | ||
| 187 | "(\$data[1] > $failRunQueue)" => 'Fail' }, | ||
| 188 | Requirements => undef, | ||
| 189 | StatusHistoryLimit => 30, | ||
| 190 | StatusChangeActions => undef, | ||
| 191 | StatusUpgradeRules => undef, | ||
| 192 | ExpireAfter => "$expireAfterSec seconds", | ||
| 193 | Description => $description, | ||
| 194 | RrdTimeCol => undef, | ||
| 195 | RrdColumns => [ '$data[20]', '$data[21]', '$data[1]', '$data[12]' ], | ||
| 196 | RrdFilter => undef, | ||
| 197 | RrdMin => undef, | ||
| 198 | RrdMax => undef, | ||
| 199 | RrdXFF => undef, | ||
| 200 | RrdCF => undef, | ||
| 201 | RrdDST => undef, | ||
| 202 | }; | ||
| 203 | |||
| 204 | # Run the validation | ||
| 205 | &validateParms(\%args,$defaultRules) || &fatal("Exiting"); | ||
| 206 | |||
| 207 | # Add the rule | ||
| 208 | my $vbObj = $self->SUPER::addVBObj(%args) || return undef; | ||
| 209 | |||
| 210 | # Now define what graphs to show on this object's page | ||
| 211 | $vbObj->addGraphGroup ( | ||
| 212 | GroupNumber => 1, | ||
| 213 | DataSourceList => undef, | ||
| 214 | Labels => 'user,system,runQueue,scanRate', | ||
| 215 | LineWidth => undef, | ||
| 216 | Colors => undef, | ||
| 217 | VLabel => undef, | ||
| 218 | Title => "$::HOST cpu", | ||
| 219 | TimeWindowList => undef, | ||
| 220 | CF => undef, | ||
| 221 | XSize => undef, | ||
| 222 | YSize => undef, | ||
| 223 | Target => undef | ||
| 224 | ); | ||
| 225 | |||
| 226 | ($vbObj); | ||
| 227 | } | ||
| 228 | |||
| 229 | 1; | ||
| 230 | __END__ |