使用jython从WebSphere PMI数据中获取webcontainer

时间:2013-09-27 13:12:11

标签: performance websphere jython websphere-8

尝试制作一个非常简单的jython脚本,以从websphere获取基本的PMI数据。获取JVM数据(如空闲堆等)很简单(并且可以正常工作)

perfName = AdminControl.completeObjectName ('type=Perf,process=PTEIRMW_APPSERVER801,*')
perfOName = AdminControl.makeObjectName (perfName)
jvmName = AdminControl.completeObjectName ('type=JVM,process=PTEIRMW_APPSERVER801,*')
params = [AdminControl.makeObjectName (jvmName), java.lang.Boolean ('false')]
sigs = ['javax.management.ObjectName', 'java.lang.Boolean']
AdminControl.invoke_jmx (perfOName, 'getStatsObject', params, sigs)

但后来我尝试为WebContainer线程池做类似的事情,但它失败了

threadPoolName = AdminControl.completeObjectName('name=WebContainer,type=ThreadPool,process=PTEIRMW_APPSERVER801,*')
threadPoolOName = AdminControl.makeObjectName (threadPoolName)
params = [AdminControl.makeObjectName (threadPoolName), java.lang.Boolean ('false')]
sigs = ['javax.management.ObjectName', 'java.lang.Boolean']
AdminControl.invoke_jmx (threadPoolOName, 'getStatsObject', params, sigs)

错误是

WASX7015E:异常运行命令:" AdminControl.invoke_jmx(threadPoolOName,' getStatsObject',params,sigs)&#34 ;;异常信息: javax.management.MBeanException javax.management.ServiceNotFoundException:不在ModelMBeanInfo中的操作getStatsObject

有什么想法吗?我特别想要WebContainer线程池(最好只有活动线程......但我可以稍后过滤掉它)

2 个答案:

答案 0 :(得分:1)

您需要从该MBean中检索stats属性:

on = AdminControl.queryNames('*,name=WebContainer,type=ThreadPool,process=PTEIRMW_APPSERVER801')
print AdminControl.getAttribute_jmx(AdminControl.makeObjectName(on), 'stats')

功能相同,这次使用WDR库(http://wdr.github.io/WDR/

print getJMXMBean1(type='ThreadPool', name='WebContainer', process='PTEIRMW_APPSERVER801').stats

忏悔:我是WDR贡献者之一。

答案 1 :(得分:0)

答案结果如下(已清理且更通用的版本):

#Get the AppServer from parameter
appServer = sys.argv[0]

perfName = AdminControl.completeObjectName ('type=Perf,process='+appServer+',*')
perfOName = AdminControl.makeObjectName (perfName)
sigs = ['javax.management.ObjectName', 'java.lang.Boolean']

# Getting the JVM Data
jvmName = AdminControl.completeObjectName ('type=JVM,process='+appServer+',*')
params = [AdminControl.makeObjectName (jvmName), java.lang.Boolean ('false')]
print AdminControl.invoke_jmx (perfOName, 'getStatsObject', params, sigs)

# Getting the threadpool data

threadPoolName = AdminControl.completeObjectName('name=WebContainer,type=ThreadPool,process='+appServer+',*')
params = [AdminControl.makeObjectName (threadPoolName), java.lang.Boolean ('false')]
print AdminControl.invoke_jmx (perfOName, 'getStatsObject', params, sigs)

但我也测试了@Martin Plonkas的答案,它也有效