Hi,
Many times we want to monitor the different modules available as part of our WebLogic Domain. WebLogic Scripting Tool (WLST) is one of the best utility which is based on Jython (The Java Version of Python Scripting) Option.
WLST not only allows to configure different resources in WebLogic Server/Domain as well as it allows a very easy way to monitor different resources available as part of WebLogic Server/Domain. We can monitor JMS/ DataSources/JDBC Parameters…etc using WLST.
Here we are going to see a very simple demonstration of using WLST to monitor DataSources and the JDBC Properties which it holds, this part of monitoring includes both the Configuration Informations as well as the Runtime informations of the dataSource.
Step1). Create a WLST Script somewhere in your file system with some name like “Monitor_Jdbc.py” inside “C:WLST_Jdbc” contents will be something like following:
############################################################################# # # @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved. # ############################################################################# connect('weblogic','weblogic','t3://localhost:7001') allServers=domainRuntimeService.getServerRuntimes(); if (len(allServers) > 0): for tempServer in allServers: jdbcServiceRT = tempServer.getJDBCServiceRuntime(); dataSources = jdbcServiceRT.getJDBCDataSourceRuntimeMBeans(); if (len(dataSources) > 0): for dataSource in dataSources: print 'ActiveConnectionsAverageCount ' , dataSource.getActiveConnectionsAverageCount() print 'ActiveConnectionsCurrentCount ' , dataSource.getActiveConnectionsCurrentCount() print 'ActiveConnectionsHighCount ' , dataSource.getActiveConnectionsHighCount() print 'ConnectionDelayTime ' , dataSource.getConnectionDelayTime() print 'ConnectionsTotalCount ' , dataSource.getConnectionsTotalCount() print 'CurrCapacity ' , dataSource.getCurrCapacity() print 'CurrCapacityHighCount ' , dataSource.getCurrCapacityHighCount() print 'DeploymentState ' , dataSource.getDeploymentState() print 'FailedReserveRequestCount ' , dataSource.getFailedReserveRequestCount() print 'FailuresToReconnectCount ' , dataSource.getFailuresToReconnectCount() print 'HighestNumAvailable ' , dataSource.getHighestNumAvailable() print 'HighestNumUnavailable ' , dataSource.getHighestNumUnavailable() print 'LeakedConnectionCount ' , dataSource.getLeakedConnectionCount() print 'ModuleId ' , dataSource.getModuleId() print 'Name ' , dataSource.getName() print 'NumAvailable ' , dataSource.getNumAvailable() print 'NumUnavailable ' , dataSource.getNumUnavailable() print 'Parent ' , dataSource.getParent() print 'PrepStmtCacheAccessCount ' , dataSource.getPrepStmtCacheAccessCount() print 'PrepStmtCacheAddCount ' , dataSource.getPrepStmtCacheAddCount() print 'PrepStmtCacheCurrentSize ' , dataSource.getPrepStmtCacheCurrentSize() print 'PrepStmtCacheDeleteCount ' , dataSource.getPrepStmtCacheDeleteCount() print 'PrepStmtCacheHitCount ' , dataSource.getPrepStmtCacheHitCount() print 'PrepStmtCacheMissCount ' , dataSource.getPrepStmtCacheMissCount() print 'Properties ' , dataSource.getProperties() print 'ReserveRequestCount ' , dataSource.getReserveRequestCount() print 'State ' , dataSource.getState() print 'Type ' , dataSource.getType() print 'VersionJDBCDriver ' , dataSource.getVersionJDBCDriver() print 'WaitingForConnectionCurrentCount ' , dataSource.getWaitingForConnectionCurrentCount() print 'WaitingForConnectionFailureTotal ' , dataSource.getWaitingForConnectionFailureTotal() print 'WaitingForConnectionHighCount ' , dataSource.getWaitingForConnectionHighCount() print 'WaitingForConnectionSuccessTotal ' , dataSource.getWaitingForConnectionSuccessTotal() print 'WaitingForConnectionTotal ' , dataSource.getWaitingForConnectionTotal() print 'WaitSecondsHighCount ' , dataSource.getWaitSecondsHighCount()
Step2). Start your WebLogic Server and Databases (Make sure that you have configured some dataSources in the Server to monitor).
Step3). Open a command prompt and then run the “setWLSEnv.cmd” or “setWLSEnv.sh” to set the CLASSPATH and PATH variables. Better you do echo %CLASSPATH% or echo $CLASSPATH to see whether the CLASSPATH is set properly or not. If you see an Empty Classpath even after running the “setWLSEnv.sh” then please refer to the Note mentioned at Step3) in the Following post: http://middlewaremagic.com/weblogic/?page_id=1492
Step4). Now run the WLST Script in the same command prompt like following:
java weblogic.WLST C:WLST_JdbcMonitor_Jdbc.py
You will see the following kind of results in the command prompt
ActiveConnectionsAverageCount 0 ActiveConnectionsCurrentCount 0 ActiveConnectionsHighCount 0 ConnectionDelayTime 25 ConnectionsTotalCount 10 CurrCapacity 10 CurrCapacityHighCount 1 DeploymentState 2 FailedReserveRequestCount 0 FailuresToReconnectCount 0 HighestNumAvailable 10 HighestNumUnavailable 0 LeakedConnectionCount 0 ModuleId TestDS Name TestDS NumAvailable 10 NumUnavailable 0 Parent [MBeanServerInvocationHandler]com.bea:Name=AdminServer,Location=AdminServer,Type=ServerRuntime PrepStmtCacheAccessCount 0 PrepStmtCacheAddCount 0 PrepStmtCacheCurrentSize 0 PrepStmtCacheDeleteCount 0 PrepStmtCacheHitCount 0 PrepStmtCacheMissCount 0 Properties {databaseName=jdbc:pointbase:server://localhost:9092/demo, user=PBPUBLIC} ReserveRequestCount 0 State Running Type JDBCDataSourceRuntime VersionJDBCDriver com.pointbase.jdbc.jdbcUniversalDriver WaitingForConnectionCurrentCount 0 WaitingForConnectionFailureTotal 0 WaitingForConnectionHighCount 0 WaitingForConnectionSuccessTotal 0 WaitingForConnectionTotal 0 WaitSecondsHighCount 0
.
.
Thanks
Jay SenSharma
December 18th, 2010 on 4:25 pm
cool stuff.
Yet I feel that using reflection the code can be simplified:
see Example 4.1. apihelper.py in
http://diveintopython.org/power_of_introspection/index.html
I haven’t tried but looks promising…
December 21st, 2011 on 6:41 pm
Hi Ravish,
Here i am giving you the script which i wrote for monitoring all data sources in multiple doamins and placing the output in a html file in a tabular format. I am unable to place all the content in the table with only one table heading. my script is printing the header part for each domain. I want one table with one single heading for all the DS information. PLease help me.
SCRIPT:
================================================
#!/usr/bin/python
import os
import time
import getopt
import sys
from java.util import Properties
from java.io import FileInputStream
from java.io import File
propInputStream = FileInputStream(“check.properties”)
configProps = Properties()
configProps.load(propInputStream)
Username = configProps.get(“username”)
Password = configProps.get(“password”)
domain_count=configProps.get(“domain_count”)
outfile = open(“ds.html”, “w”)
i=1
while (int(i) 0):
print >>outfile, “””
JDBC CONNECTION POOLS
“””
print >>outfile, “ServerNameStateActive Connections Current CountFailures To Reconnect CountLeaked Connection CountNum Available”
for tempServer in allServers:
jdbcServiceRT = tempServer.getJDBCServiceRuntime();
dataSources = jdbcServiceRT.getJDBCDataSourceRuntimeMBeans();
if (len(dataSources) > 0):
ds_counter = 1
for dataSource in dataSources:
Name = dataSource.getName()
Server = tempServer.getName()
State = dataSource.getState()
ActiveConnectionsCurrentCount = dataSource.getActiveConnectionsCurrentCount()
FailuresToReconnectCount = dataSource.getFailuresToReconnectCount()
LeakedConnectionCount = dataSource.getLeakedConnectionCount()
NumAvailable = dataSource.getNumAvailable()
if (int(ActiveConnectionsCurrentCount) > 0):
print >>outfile, ”’%s%s%s%s%s%s%s”’ % (Server,Name,State,ActiveConnectionsCurrentCount,FailuresToReconnectCount,LeakedConnectionCount,NumAvailable)
ds_counter += 1
ins_counter += 1
print >>outfile, “””
“””
except:
print ‘****** UNABLE TO CONNECT TO THE SERVER —— ‘+ serverUrl
disconnect()
i = i + 1
PROPERTIES FILE:
==================================
username=/WLST_Scripts/MyUserConfigFile.secure
password=/WLST_Scripts/MyUserKeyFile.secure
domain_count=10
serverUrl.1=t3://localhost:10080
serverUrl.2=t3://localhost:20080
serverUrl.3=t3://localhost:30080
serverUrl.4=t3://localhost:40080
serverUrl.5=t3://localhost:50080
serverUrl.6=t3://localhost:60080
serverUrl.7=t3://localhost:70080
serverUrl.8=t3://localhost:80080
serverUrl.9=t3://localhost:90080
serverUrl.10=t3://localhost:100080
OUTPUT:
==========
I couldnt able to paste the output.
Please help me here.
thanks
December 25th, 2011 on 11:49 am
Hi Pavan,
I have fixed your script and mailed you. The new script would only have a single header for all the domains as you wanted it to be.
Keep Posting 🙂
Regards,
Ravish Mody