-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathget_webcontainer_active_threads.py
More file actions
executable file
·87 lines (70 loc) · 3.24 KB
/
get_webcontainer_active_threads.py
File metadata and controls
executable file
·87 lines (70 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env wsadmin.sh -lang jython
#
# Script: get_webcontainer_active_threads.py
# Purpose: Display the active thread count for the WebContainer thread pool
# Usage: wsadmin.sh -lang jython -f get_webcontainer_active_threads.py [server_name]
# If server_name is not provided, will use the first application server found
#
import sys
import java.lang.System as system
def printUsage():
print "Usage: wsadmin.sh -lang jython -f get_webcontainer_active_threads.py [server_name]"
print " If server_name is not provided, will use the first application server found"
def getServerName():
if len(sys.argv) > 0:
return sys.argv[0]
else:
# Get the first application server if no server name is provided
servers = AdminConfig.list('Server').splitlines()
for server in servers:
serverType = AdminConfig.showAttribute(server, 'serverType')
if serverType == 'APPLICATION_SERVER':
return AdminConfig.showAttribute(server, 'name')
print "Error: No application server found in the cell"
sys.exit(1)
def getWebContainerThreadPoolStats(serverName):
serverID = AdminConfig.getid('/Server:' + serverName + '/')
if not serverID:
print "Error: Server '%s' not found" % serverName
return None
nodeName = serverID.split('/nodes/')[1].split('/')[0]
# Get the Performance MBean for the server
perf = AdminControl.completeObjectName('WebSphere:type=Perf,node=%s,process=%s,*' % (nodeName, serverName))
objName = AdminControl.makeObjectName(perf)
if not perf :
print "Error: Performance MBean not found for server '%s'" % serverName
return None
# Build the ObjectName for the WebContainer thread pool
threadPoolMBeanQuery = "WebSphere:type=ThreadPool,name=WebContainer,process=" + serverName + ",*"
threadPoolMBeanName = AdminControl.queryNames(threadPoolMBeanQuery)
# Prepare parameters and signatures for invoke_jmx
params = [AdminControl.makeObjectName(threadPoolMBeanName), java.lang.Boolean("true")]
signatures = ["javax.management.ObjectName", "java.lang.Boolean"]
try:
# Invoke the getStatsObject method with explicit parameters and signatures
webContainerStats = AdminControl.invoke_jmx(objName, "getStatsObject", params, signatures)
if webContainerStats:
# Extract the ActiveCount from the stats object
activeCountStat = webContainerStats.getStatistic('ActiveCount')
poolSize = webContainerStats.getStatistic('PoolSize')
activeCount = activeCountStat.getCurrent()
maxSize = poolSize.getUpperBound()
print("Active WebContainer Threads for '%s/%s': %s/%s" % (serverName, nodeName, str(activeCount), str(maxSize)))
else:
print "Could not retrieve WebContainer stats object."
except Exception, e:
print "An error occurred while invoking getStatsObject via JMX: %s" % e
return None
def main():
try:
serverName = getServerName()
getWebContainerThreadPoolStats(serverName)
except SystemExit:
# Handle the sys.exit() call
pass
except:
print "Unexpected error occurred:"
print sys.exc_info()[1]
printUsage()
# Execute the main function
main()