Goran_Morchel

set PMI with Jython in WAS using wsadmin.sh

Discussion created by Goran_Morchel on Feb 13, 2012
I was building a script in Jython to set all the WebSphere settings needed to activate the introscope agent. In case someone is struggling with the setPMI in Jython (like I did), I'd like to share it.

I actually found two ways to do it. Here they are:
################################################################################
# Version 1
################################################################################
def callsetcustpmi(serverid):

#--------------------------------------------------------------------

# set PMI for several counters

#--------------------------------------------------------------------

# get PMI-ID

pmi = AdminConfig.list('PMIService', serverid)

#  activate PMI and set to Custom 

AdminConfig.modify(pmi, [['enable', 'true'], ['statisticSet','custom']])

message = "PMI aktivieren und Statistic Set auf Custom aendern."

printprot(message)

# call function setcustpmi() to activate the below defined counters

# Definition of IDs: http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rprf_datacounter6.html

setcustpmi( serverid, "connectionPoolModule", [1,2,5,6,7,13] )

setcustpmi( serverid, "j2cModule", [1,2,5,6,7,13] )

setcustpmi( serverid, "servletSessionsModule", [1,2,6,7,17] )

setcustpmi( serverid, "threadPoolModule", [3,4] )

speichern()



def setcustpmi( serverid, NameModule, newabled ):

#--------------------------------------------------------------------

# Function being called from callsetcustpmi() to activate several different PMI counters

#--------------------------------------------------------------------

# get all PMI-Modules

pmim = AdminConfig.list('PMIModule', serverid)

# get rid of [ and ]

pmiList = AdminConfig.showAttribute(pmim,'pmimodules')[1:-1]

# split

pmiList = pmiList.split(" ")

for modules in pmiList:


modName = AdminConfig.showAttribute(modules,'moduleName')


if modName == NameModule:



modconf = modules



# here we enable the counters



AdminConfig.modify(modconf, [ ['enable',newabled] ])

################################################################################
# Version 2: This is a simpler way to do the same thing:
################################################################################




def setcustpmialt( serverid ):

#--------------------------------------------------------------------

# simple set PMI for one or more counters

#--------------------------------------------------------------------

serverName = getNamefromId(serverid)

objString = 'type=Perf,process=' + serverName + ',*'

perfName = AdminControl.completeObjectName(objString)

print "perfName: " + perfName

print "------------------------------------------------------------------------------------------------------ "

perfOName = AdminControl.makeObjectName(perfName)

print perfOName

# define Modules und IDs that need to be activated: Module1=ID1,ID3:Module2=ID2,ID3

params = ['jvmRuntimeModule=3,4,5', java.lang.Boolean ('false')] 

sigs  = ['java.lang.String', 'java.lang.Boolean']

# Set PMI to custom

AdminControl.invoke_jmx(perfOName, 'setCustomSetString', params, sigs)

# persist changes, this is important otherwise your pmi will only be enabled in runtime. I did not find this on any IBM website

AdminControl.invoke (perfName, 'savePMIConfiguration')
Regarding the 'serverid':
nodelist = AdminConfig.list('Node').split("\n")
#split list, select proper node here
nodename = getNamefromId(node)
serverid = AdminConfig.getid('/Node:' + nodename + '/')

Outcomes