Weblogic简介
Oracle WebLogic Server 是一个统一的可扩展平台,专用于开发、部署和运行 Java 应用等适用于本地环境和云环境的企业应用。它提供了一种强健、成熟和可扩展的 Java Enterprise Edition (EE) 和 Jakarta EE 实施方式。
背景说明
近期客户要求对现有系统的Weblogic中间件DOMAIN域(Server,JDBC)配置信息进行采集分析。以便于对DOMAIN域(Server,JDBC)配置进行规范化、统一化配置管理,以及协助问题定位等。
采集指标
AdminServer名称
控制台地址上下文
域的版本
域的路径
Server名称
监听地址
监听端口
SSL监听端口
是否启用IIOP (1:启用,0:未启用)
粘滞线程最长时间
...
数据源名称
数据源的目标服务器
数据源的URL
数据源属性配置
初始容量
最大容量
最小容量
开启保留时测试连接 (1:启用,0:未启用)
测试频率(秒数)
收缩频率(秒数)
非活动连接超时秒数
...
采集方案
WebLogic 脚本工具(WLST)是一个命令行脚本环境,您可以用它来创建、管理和监控 WebLogic 域。它基于Java脚本解释器,Jython。除了支持标准的 Jython 功能(如本地变量、条件变量和流量控制语句)外,WLST 还提供一组特定于 WebLogic 服务器的脚本功能(命令)。您可以按照 Jython 语言语法扩展 WebLogic 脚本语言以满足您的需求。
接下来,我们将用一组脚本来进行说明:
1. weblogic_getparams.sh(实现采集总体框架)
2. weblogic_getparams.py(实现Weblogic指标数据采集)
3. auth_info.cfg(配置Weblogic控制台登录授权信息)
4. 采集结果文件:
result_wls_params.txt
result_jdbc_params.txt
实现脚本
#!/bin/bash
##. $HOME/.bash_profile
## Check parameters
if [ $# -eq 2 ]
then
## The Weblogic Product install directory
WLS_HOME=$1
## The Weblogic Console authorization info
AUTH_FILE=$2
else
echo "###########################################################################################################"
echo "usage: sh $0 WLS_HOME AUTH_FILE"
echo "eg1: sh $0 /weblogic/Oracle/Middleware/wlserver_10.3 auth_info.cfg"
echo
echo "function description:"
echo "Get weblogic server config parameters"
echo "The "WLS_HOME" : The Weblogic Product install directory (grep "WL_HOME=" setDomainEnv.sh)."
echo "The "AUTH_FILE" : The Weblogic Console authorization file (eg: /weblogic/shell/maintain/auth_info.cfg)."
echo
echo "Platform :All Linux Based Platform and HP-UX"
echo "version: 1.0"
echo "author: sunchangcheng@shsnc.com"
echo "create: 2021-12-20."
echo "###########################################################################################################"
exit
fi
## Define variable
WORK_HOME=$(dirname $(readlink -f "$0"))
PYTHON_SCRIPT="${WORK_HOME}/weblogic_getparams.py"
WLS_PARAMS_FILE="${WORK_HOME}/result_wls_params.txt"
JDBC_PARAMS_FILE="${WORK_HOME}/result_jdbc_params.txt"
if [ -f "${WLS_HOME}" ]
then
echo [`date +%Y-%m-%d %H:%M:%S`]" The WLS_HOME [${WLS_HOME}] is non-exist, exit !"
exit
fi
echo [`date +%Y-%m-%d %H:%M:%S`]" ======================[BEGIN]====================================================="
# Use wlst.sh to execute pyhton shell
${WLS_HOME}/common/bin/wlst.sh ${PYTHON_SCRIPT} ${AUTH_FILE} ${WLS_PARAMS_FILE} ${JDBC_PARAMS_FILE}
echo [`date +%Y-%m-%d %H:%M:%S`]" ======================[END]======================================================="
## Get weblogic server config parameters
# encoding:utf-8
AUTH_FILE = sys.argv[1]
WLS_PARAMS_FILE = sys.argv[2]
JDBC_PARAMS_FILE = sys.argv[3]
focfg = open(AUTH_FILE, "rb")
fowlstxt = open(WLS_PARAMS_FILE, "wb")
fojdbctxt = open(JDBC_PARAMS_FILE, "wb")
########################################################
##获取WLS相关配置信息
def getWLSparams():
print >>fowlstxt, "%-s" % ("========================================================================================================================")
##监听地址
AdminServerName = cmo.getAdminServerName()
##AdminServer名称
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,AdminServerName,"AdminServerName",cmo.getAdminServerName())
##AdminServer协议
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,AdminServerName,"AdministrationProtocol",cmo.getAdministrationProtocol())
##控制台地址上下文
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,AdminServerName,"ConsoleContextPath",cmo.getConsoleContextPath())
##域的版本
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,AdminServerName,"DomainVersion",cmo.getDomainVersion())
##域的名称
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,AdminServerName,"DomainName",cmo.getName())
##域的路径
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,AdminServerName,"DomainHome",cmo.getRootDirectory())
servers=cmo.getServers()
for server in servers:
print >>fowlstxt, "%-s" % ("----------------------------------------------------------------------------------------------------")
##Server名称
serverName=server.getName()
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"ServerName",server.getName())
##监听地址
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"ListenAddress",server.getListenAddress())
##启用监听端口
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"ListenPortEnabled",server.isListenPortEnabled())
##监听端口
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"ListenPort",server.getListenPort())
##启用SSL监听端口
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"SSLListenPortEnabled",server.getSSL().isEnabled())
##SSL监听端口
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"SSLListenPort",server.getSSL().getListenPort())
##启用IIOP
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"IIOPEnabled",server.isIIOPEnabled())
##启用本地IO
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"NativeIOEnabled",server.isNativeIOEnabled())
##默认队列中可以用作套接字读取器的执行线程的百分比
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"ThreadPoolPercentSocketReaders",server.getThreadPoolPercentSocketReaders())
##最大打开套接字数
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"MaxOpenSockCount",server.getMaxOpenSockCount())
##粘滞线程最长时间
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"StuckThreadMaxTime",server.getStuckThreadMaxTime())
##粘滞线程计时器间隔
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"StuckThreadTimerInterval",server.getStuckThreadTimerInterval())
##应该允许的积压的新TCP连接请求的数量
print >>fowlstxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,serverName,"AcceptBacklog",server.getAcceptBacklog())
##获取JDBC相关配置信息
def getJDBCparams():
dataSources=cmo.getJDBCSystemResources()
for dataSource in dataSources:
print >>fojdbctxt, "%-s" % ("----------------------------------------------------------------------------------------------------")
##数据源名称
jdbcName=dataSource.getName()
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"JdbcName",jdbcName)
##数据源配置文件路径
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"SourcePath",dataSource.getSourcePath())
##数据源的目标服务器
targets=dataSource.getTargets()
for target in targets:
print >>fojdbctxt, "%-25s- %-20s- %-40s: %s" % (adminurl,jdbcName,"Targets",target.getName())
cd("/JDBCSystemResources/"+jdbcName+"/JDBCResource/"+jdbcName+"/JDBCDriverParams/"+jdbcName)
##数据库的URL
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"Url",cmo.getUrl())
##驱动程序类名称
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"DriverName",cmo.getDriverName())
###数据源属性配置
cd("/JDBCSystemResources/"+jdbcName+"/JDBCResource/"+jdbcName+"/JDBCDriverParams/"+jdbcName+"/Properties/"+jdbcName)
properties=cmo.getProperties()
for proper in properties:
print >>fojdbctxt, "%-25s- %-20s- %-40s: %s=%-s" % (adminurl,jdbcName,"Properties",proper.getName(),proper.getValue())
cd("/JDBCSystemResources/"+jdbcName+"/JDBCResource/"+jdbcName+"/JDBCConnectionPoolParams/"+jdbcName)
##初始容量
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"InitialCapacity",cmo.getInitialCapacity())
##最大容量
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"MaxCapacity",cmo.getMaxCapacity())
##最小容量
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"MinCapacity",cmo.getMinCapacity())
##语句高速缓存类型
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"StatementCacheType",cmo.getStatementCacheType())
##语句高速缓存大小
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"StatementCacheSize",cmo.getStatementCacheSize())
##保留时测试连接
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"TestConnectionsOnReserve",cmo.isTestConnectionsOnReserve())
##测试频率(秒数)
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"TestFrequencySeconds",cmo.getTestFrequencySeconds())
##测试表表名
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"TestTableName",cmo.getTestTableName())
##信任空闲池连接的(秒数)
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"SecondsToTrustAnIdlePoolConnection",cmo.getSecondsToTrustAnIdlePoolConnection())
##收缩频率(秒数)
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"ShrinkFrequencySeconds",cmo.getShrinkFrequencySeconds())
##重试创建连接的频率(秒数)
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"ConnectionCreationRetryFrequencySeconds",cmo.getConnectionCreationRetryFrequencySeconds())
##登录延迟
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"LoginDelaySeconds",cmo.getLoginDelaySeconds())
##非活动连接超时秒数
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"InactiveConnectionTimeoutSeconds",cmo.getInactiveConnectionTimeoutSeconds())
##最大等待连接数
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"HighestNumWaiters",cmo.getHighestNumWaiters())
##连接保留超时(秒数)
print >>fojdbctxt, "%-25s- %-20s- %-40s: %-s" % (adminurl,jdbcName,"ConnectionReserveTimeoutSeconds",cmo.getConnectionReserveTimeoutSeconds())
############################################################
for authinfo in focfg:
autharray = authinfo.split(",")
if len(autharray) < 3:
continue
###cfgfile = autharray[0].strip()
###keyfile = autharray[1].strip()
###adminurl = autharray[2].strip()
###connect(userConfigFile=cfgfile,userKeyFile=keyfile,url=adminurl)
UserName = autharray[0].strip()
PassWord = autharray[1].strip()
AdminUrl = autharray[2].strip()
connect(UserName,PassWord,AdminUrl)
##获取WLS相关配置信息
getWLSparams()
##获取JDBC相关配置信息
getJDBCparams()
disconnect()
focfg.close()
fowlstxt.close()
fojdbctxt.close()
exit()
weblogic,password,t3://10.243.*.*:7011
weblogic,password,t3://10.243.*.*:7012
weblogic,password,t3://10.243.*.*:7013
注:控制台登录授权信息也可以通过wlst自带的storeUserConfig()方法进行加密处理,具体使用方法可百度搜索查看。
4. 采集结果样例
4.1 result_wls_params.txt
格式说明:以冒号”:”分割
URL:ServerName:属性名称:属性值
4.2 result_jdbc_params.txt
格式说明:以冒号”:”分割
URL:JDBC名称:属性名称:属性值
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129676.html
阅读 1249·2023-01-11 13:20
阅读 1558·2023-01-11 13:20
阅读 1012·2023-01-11 13:20
阅读 1680·2023-01-11 13:20
阅读 3971·2023-01-11 13:20
阅读 2519·2023-01-11 13:20
阅读 1355·2023-01-11 13:20
阅读 3486·2023-01-11 13:20