Escolar Documentos
Profissional Documentos
Cultura Documentos
py
# Purpose: Display user requested information about
#
WebSphere Application Server (WSAS) resources.
# History:
# date
ver who what
# -------- --- --- ---------# 10/09/07 0.8 HG Fix - Ratio needed * 100.0
#
Expanded threadpool column headings
# 10/09/07 0.7 HG Add - test for "Help" before things start
# 10/08/27 0.6 HG Add - displayDict() & use in theadpool()
# 10/08/20 0.5 HG Fix - typo in Usage
# 10/08/20 0.4 HG Fix - AdminConfig.getAttributes() is wrong
#
AdminControl.getAttributes() is right (sigh)
# 10/08/20 0.3 HG Fix - Add exception check in threadpool() based upon clien
t issue
# 10/08/19 0.2 HG Fix - Add the threadpool() routine specifics
# 10/07/22 0.1 HG Fix - the Usage "example", added badInfo mapped message
#---------------------------------------------------------------------'''Command: %(cmdName)s\n
Purpose: wsadmin script used to display user specified information about
WebSphere Application Server resources.\n
Version: %(version)s
Updated: %(updated)s\n
Usage: %(cmdName)s [options]\n
Required switches/options:
-i | --info
<value> = Type of information being requested
-s | --serverName <value> = Target serverName\n
Optional switches/options:
-n | --nodeName <value> = Target nodeName\n
Information types/values:
connectionpool - Display Connection Pool details
heapsize
- Display Heap Size details
threadpool
- Display Thread Pool details
sessions
- Display Session Details\n
Notes:
- Long form option values may be separated/delimited from their associated
identifier using either a space, or an equal sign ('=').\n
- Short form option values may be sepearated from their associated letter
using an optional space.\n
- Text containing blanks must be enclosed in double quotes.\n
Examples:
wsadmin -f %(cmdName)s.py -i heapsize -s server1 -n node01\n'''
import os, re, sys, getopt;
if 'Help' not in dir() :
try :
import Help;
except :
print 'Required module "Help" unavailable.';
sys.exit();
__scriptName__ = 'check_was';
__version__
= '0.8';
__updated__
= '07 Sept 2010';
#--------------------------------------------------------------------# Name: beanNameAsDict()
# Role: Parse the specified MBean and return a dictionary of the name
#
value pairs
#--------------------------------------------------------------------def beanNameAsDict( bean ) :
'beanNameAsDict() - Parse the specified MBean and return a dictionary of the n
ame value pairs'
result = {};
for pair in bean.split( ':', 1 )[ 1 ].split( ',' ) :
n, v = pair.split( '=', 1 );
result[ n ] = v;
return result;
#--------------------------------------------------------------------# Name: callerName
# Role: Utility routine used to determine, and return the name of the
#
calling function.
# Note: Dependends on sys._getframe()
# See: http://code.activestate.com/recipes/66062/
#--------------------------------------------------------------------def callerName() :
"callerName() - Returns the name of the calling routine (or '?')"
return sys._getframe( 1 ).f_code.co_name;
#--------------------------------------------------------------------# Name: configurable()
# Role: Return true (1) if AdminConfig object is available, false (0) otherwise
#--------------------------------------------------------------------def configurable() :
'configurable() - Return true (1) if AdminConfig object is available, false (0
) otherwise'
try :
host = AdminConfig.list( 'Server' );
result = 1;
# True = AdminConfig object is available
except :
result = 0;
# False = AdminConfig object not availabl
e
return result;
#--------------------------------------------------------------------# Name: configIdAsDict
# Role: Parse a config ID and return a dictionary of name/value pairs
# Note: Exception handler requires sys module
#
The keys in the returned dictionary come from the configID, so
#
are unlikely to match your defect expectations about exactly
#
what values are used (e.g., 'nodes' instead of "Node")
#--------------------------------------------------------------------def configIdAsDict( configId ) :
'configIdAsDict( configId ) - Given a configID, return a dictionary of the nam
e/value components.'
funName = callerName();
# Name of this function
result = {};
# Result is a dictionary
hier
= [];
# Initialize to simplifiy checks
try :
# Be prepared for an error
#----------------------------------------------------------------# Does the specified configID match our RegExp pattern?
# Note: mo == Match Object, if mo != None, a match was found
#----------------------------------------------------------------if ( configId[ 0 ] == '"' ) and ( configId[ -1 ] == '"' ) and ( configId.cou
nt( '"' ) == 2 ) :
node = nid;
if not node :
print badNode % locals();
#------------------------------------------------------------------# Does the specified serverName exist (within the scope of the
# specified node)?
# Note: A scope of None is identical to not specifying a scope
#------------------------------------------------------------------servers = [];
for sid in AdminConfig.list( 'Server', node ).splitlines() :
if sid.startswith( serverName + '(' ) :
servers.append( sid );
if len( servers ) < 1 :
print badServer % locals();
sys.exit();
elif len( servers ) > 1 :
print ambigServer % locals();
nodes = [];
for sid in servers :
nodes.append( configIdAsDict( sid )[ 'nodes' ] );
print 'Specify one of the following nodes using the --nodeName option: ' + (
', '.join( nodes ) );
sys.exit();
server = servers[ 0 ];
# print 'Request for %s on %s' % ( info, server );
if info == 'heapsize' :
heapsize( server );
elif info == 'threadpool' :
threadpool( server );
else :
print 'Not yet implemented: "%s"' % info
#--------------------------------------------------------------------# Name: MB()
# Role: Convert the specified (integer) value [bytes] into MegaBytes
#--------------------------------------------------------------------def MB( val ) :
'MB() - Convert specified integer (byte) value into MegaBytes'
return int( val ) / ( 1024.0 * 1024.0 );
#--------------------------------------------------------------------# Name: MBattrAsDict
# Role: Utility routine used to return a dictionary of attributes for
#
the specified mbean
# Note: Depends upon availability of WSAS Admin Objects via sys.modules
# History:
# when ver who what
# -------- --- --- --------------------------------------------------# 09/11/10 0.1 rag Add - Add 'Modifiable' value to result
# 09/04/08 0.0 rag New - insight obtained while writing the book
#--------------------------------------------------------------------def MBattrAsDict( mbean ) :
"MBattrAsDict( mbean ) - Given an MBean string, return a dictionary of it's at
tributes."
funName = callerName();
# Name of this function
result = {};
# Result is a dictionary
# Name: parseOpts()
# Role: Process the user specified (command line) options
#--------------------------------------------------------------------def parseOpts( cmdName ) :
shortForm = 'i:n:s:';
longForm = 'info=,nodeName=,serverName='.split( ',' );
badOpt
= '%(cmdName)s: Unknown/unrecognized parameter%(plural)s: %(argStr)s
\n';
optErr
= '%(cmdName)s: Error encountered processing: %(argStr)s\n';
problem = '%(cmdName)s: Error option processing problem: %(opt)s\n';
try :
opts, args = getopt.getopt( sys.argv, shortForm, longForm );
except getopt.GetoptError :
argStr = ' '.join( sys.argv );
print optErr % locals();
Usage( cmdName );
#------------------------------------------------------------------# Initialize the Opts dictionary using the longForm key identifiers
#------------------------------------------------------------------Opts = {};
for name in longForm :
if name[ -1 ] == '=' :
name = name[ :-1 ]
Opts[ name ] = None;
#------------------------------------------------------------------# Process the list of options returned by getopt()
#------------------------------------------------------------------for opt, val in opts :
if opt in ( '-i', '--info' )
: Opts[ 'info'
] = val
elif opt in ( '-n', '--nodeName' ) : Opts[ 'nodeName' ] = val
elif opt in ( '-s', '--serverName' ) : Opts[ 'serverName' ] = val
else :
print problem % locals();
#------------------------------------------------------------------# Check for unhandled/unrecognized options
#------------------------------------------------------------------if ( args != [] ) :
# If any unhandled parms exist => error
argStr = ' '.join( args );
plural = '';
if ( len( args ) > 1 ) : plural = 's';
print badOpt % locals();
Usage( cmdName );
#------------------------------------------------------------------# Return a dictionary of the user specified command line options
#------------------------------------------------------------------return Opts;
#--------------------------------------------------------------------# Name: threadpool()
# Role: Display information about the WebContainer threadpool for the
#
specified server
#--------------------------------------------------------------------def threadpool( serverID ) :
'threadpool() - Display info about the threadpools for the specified server'
#
#
#
#