• weblogic创建domain 域 以及创建connectionpool 连接资源池


    # 创建域
    domainTemplate = 'C:/python/appserver/Oracle/Middleware/wlserver_10.3/common/templates/domains/wls.jar'
    port = 7001
    user = 'weblogic'
    password = 'weblogic0'
    domainName = 'python_domain'
    jdkHome = 'C:/python/appserver/Oracle/Middleware/jdk160_29'
    # Weblogic Domain Template 
    # Use Basic Domain Template
    readTemplate(domainTemplate)
    
    # Config AdminServer Listen Address and Port
    cd('Servers/AdminServer')
    set('ListenAddress','')
    set('ListenPort', port)
    
    # Config username and password of Console User
    cd('/')
    # 'Security/base_domain/User/weblogic' The 'weblogic' is username
    cd('Security/base_domain/User/'+ user)
    cmo.setPassword(password)
    
    # If the domain already exists, overwrite the domain
    setOption('OverwriteDomain', 'true')
    # Config home directory for the JVM to be used when starting the weblogic server
    setOption('JavaHome',jdkHome )
    # Config the Domain folder path
    writeDomain('C:/python/appserver/Oracle/Middleware/user_projects/domains/'+ domainName)
    
    # Close Template
    closeTemplate()
    
    # Exit script
    exit()
    
    
    #创建连接池
    # Modify these values as necessary
    url = '127.0.0.1:7001'
    username = 'weblogic'
    password = 'weblogic0'
    dsName = 'mysql_ds'
    dsJNDIName = 'jdbc/mysql'
    targetName = 'AdminServer'
    initialCapacity = 1
    maxCapacity = 10
    capacityIncrement = 1
    driverName = 'com.mysql.jdbc.Driver'
    driverURL = 'jdbc:mysql://localhost:3306/crawler'
    driverUsername = 'root'
    driverPassword = 'root'
    
    # Connect to administration server
    connect(username, password, url)
    
    # Check if data source already exists
    try:
        cd('/JDBCSystemResources/' + dsName)
        print 'The JDBC Data Source ' + dsName + ' already exists.'
        exit()
    except WLSTException:
        pass
    
    print 'Creating new JDBC Data Source named ' + dsName + '.'
    
    edit()
    startEdit()
    cd('/')
    
    # Save reference to target server
    targetServer = getMBean('/Servers/' + targetName)
    
    # Create data source
    jdbcSystemResource = create(dsName, 'JDBCSystemResource')
    jdbcResource = jdbcSystemResource.getJDBCResource()
    jdbcResource.setName(dsName)
    
    # Set JNDI name
    jdbcResourceParameters = jdbcResource.getJDBCDataSourceParams()
    jdbcResourceParameters.setJNDINames([dsJNDIName])
    jdbcResourceParameters.setGlobalTransactionsProtocol('TwoPhaseCommit')
    
    # Create connection pool
    connectionPool = jdbcResource.getJDBCConnectionPoolParams()
    connectionPool.setInitialCapacity(initialCapacity)
    connectionPool.setMaxCapacity(maxCapacity)
    connectionPool.setCapacityIncrement(capacityIncrement)
    
    # Create driver settings
    driver = jdbcResource.getJDBCDriverParams()
    driver.setDriverName(driverName)
    driver.setUrl(driverURL)
    driver.setPassword(driverPassword)
    driverProperties = driver.getProperties()
    userProperty = driverProperties.createProperty('user')
    userProperty.setValue(driverUsername)
    
    # Set data source target
    jdbcSystemResource.addTarget(targetServer)
    
    # Activate changes
    save()
    activate(block='true')
    print 'Data Source created successfully.'
    exit()
    
    
    #监控weblogic
    
    # WLST WebLogic Server Monitoring Script
    # Author: Madan M Noru
    # This script can be used to monitor JVM, EXECUTE QUEUE, JDBC and JMS Resources 
    # of all the WebLogic Instances running in a domain.
    
    # NOTE: If you are unable to run this script, it could be an indentation problem. Please post your E-mail Id, I can send you the script.
    
    # import pymysql
    while True:
        import time
        print(time.strftime("%Y-%m-%d %X"))
        Now = time.localtime(time.time())
        timestr=time.strftime("%Y-%m-%d %X")
        print(timestr)
        print('=========================')
        username = 'weblogic'
        password = 'weblogic0'
        url = 't3://127.0.0.1:7001'
        urldict = {}
        connect(username, password, url)
        serverlist = adminHome.getMBeansByType('Server')
        print(serverlist)
    
        for svr in serverlist:
            # urldict['' + svr.getName() + ''] = str(svr.getListenPort())
            urldict[svr.getName()] = 't3://' + svr.getListenAddress() + ':' + str(svr.getListenPort())
        disconnect()
        # curTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        fjvm = open("jvm.txt","w")
        fjvm.truncate()
        fjvm.close()
        fpools = open("pools.txt","w")
        fpools.truncate()
        fpools.close()
        for svr, url in urldict.items():
            try:
                connect('weblogic', 'weblogic0', 't3://127.0.0.1:7001')
                jvmrtlist = home.getMBeansByType('JVMRuntime')
                print(jvmrtlist)
                print(' ')
    
                print('The Runtime Stats of Server: ' + svr)
                print(' ')
                print('JVM')
                print(' ')
                print('FreeJVM          usedJVM           totalJVM           persentJVM')
                print(' ')
                for jvmRT in jvmrtlist:
                    freejvm = jvmRT.getAttribute("HeapFreeCurrent")
                    usedjvm = jvmRT.getAttribute('HeapSizeCurrent')
                    totaljvm = jvmRT.getAttribute("HeapSizeMax")
                    persentjvm = jvmRT.getAttribute("HeapFreePercent")
                    print(freejvm, ' ', usedjvm, ' ', totaljvm,' ',persentjvm)
                    print(' ')
                    print('------------------------------------------------')
                    # 获取系统时间(只取分:秒)
                    f = open("jvm.txt", "a")
                    f.write(str(timestr)+','+str('base_domain')+','+str(svr)+','+str(freejvm)+','+str(usedjvm)+','+str(totaljvm)+','+str(persentjvm))
                    f.write('
    ')
                    print('===============1')
                    f.close()
                    # time.sleep(5)
    
                # 注释掉部分为执行队列的监控
                #               eqrtlist=home.getMBeansByType('ExecuteQueueRuntime')
                #               print ' '
                #               print ' '
                #               print 'EXECUTE QUEUES'
                #               print ' '
                #               print 'ExecuteQueueName TotalCount CurrIdleCount PendRequestCurrCount ServicedRequestTotalCount'
                #               print ' '
                #               for eqRT in eqrtlist:
                #                       eqname = eqRT.getAttribute("Name")
                #                       eqtthreads = eqRT.getAttribute("ExecuteThreadTotalCount")
                #                       eqithreads = eqRT.getAttribute("ExecuteThreadCurrentIdleCount")
                #                       eqqc = eqRT.getAttribute("PendingRequestCurrentCount")
                #                       eqthrougp = eqRT.getAttribute("ServicedRequestTotalCount")
                #                       print eqname,' ',eqtthreads,' ',eqithreads,' ',eqqc,' ',eqthrougp
                #                       print ' '
                #
                poolrtlist = home.getMBeansByType('JDBCConnectionPoolRuntime')
                print(' ')
                print(' ')
                print('JDBC CONNECTION POOLS')
    
                print('Name Maxcapacity ActiveCurrent ActiveHighCount WaitSecondsHighCount WaitingCurrentCount State')
                print(' ')
                for poolRT in poolrtlist:
                    pname = poolRT.getName()
                    ptype = 'normal'
                    pmaxcapacity = poolRT.getAttribute("MaxCapacity")
                    paccc = poolRT.getAttribute("ActiveConnectionsCurrentCount")
                    paverage=poolRT.getAttribute("ActiveConnectionsAverageCount")
                    # pachc = poolRT.getAttribute("ActiveConnectionsHighCount")
                    # pwshc = poolRT.getAttribute("WaitSecondsHighCount")
                    # pwfccc = poolRT.getAttribute("WaitingForConnectionCurrentCount")
                    pstate = poolRT.getAttribute("State")
                    print(pname, ' ', pmaxcapacity, ' ', paccc,  '  ', pstate)
                    print(' ')
                    print('-------------------------------------------------------------')
                    f = open("pools.txt", "a")
                    f.write(str(timestr)+','+str(pname)+','+str(svr)+','+str(ptype)+','+str(pstate)+','+str(paccc)+','+str(pmaxcapacity))
                    f.write('
    ')
                    f.close()
                domainRuntime()
                # cd('ServerRuntimes/'+svr+'/WorkManagerRuntimes/weblogic.kernel.Default')
                cd('ServerRuntimes/' + svr + '/ThreadPoolRuntime/ThreadPoolRuntime')
                # print(ls())
    
                print('-----------------------------------------------------------------')
    
                jmsrtlist = home.getMBeansByType('JMSDestinationRuntime')
                print(' ')
                print(' ')
                print('JMS DESTINATIONS')
                print(' ')
                print('Name ByteCurr Pending Received High MsgCurr Pending High Received ConsumersTotal')
                print(' ')
                for jmsRT in jmsrtlist:
                    jmsname = jmsRT.getAttribute("Name")
                    jmsbcc = jmsRT.getAttribute("BytesCurrentCount")
                    jmsbpc = jmsRT.getAttribute("BytesPendingCount")
                    jmsbrc = jmsRT.getAttribute("BytesReceivedCount")
                    jmsbhc = jmsRT.getAttribute("BytesHighCount")
                    jmsmcc = jmsRT.getAttribute("MessagesCurrentCount")
                    jmsmpc = jmsRT.getAttribute("MessagesPendingCount")
                    jmsmhc = jmsRT.getAttribute("MessagesHighCount")
                    jmsmrc = jmsRT.getAttribute("MessagesReceivedCount")
                    jmsctc = jmsRT.getAttribute("ConsumersTotalCount")
                    print(jmsname, ' ', jmsbcc, ' ', jmsbpc, ' ', jmsbrc, ' ', jmsbhc, ' ', jmsmcc, ' ', jmsmpc, ' ', jmsmhc, ' ', jmsmrc, ' ',
                          jmsctc)
                    print(' ')
                    print('-------------------------------------------------------------------')
                    # 获取系统时间(只取分:秒)
                    disconnect()
            except:
                print("Skipping " + svr)
                continue
        java.lang.Thread.sleep(5000)
  • 相关阅读:
    第九届蓝桥杯省赛c/c++真题明码题解答案,另类excel解法思路
    Windows下将Python源代码.py文件封装成exe可执行文件方法
    windows下python自带的pip安装速度过慢解决方案
    解决:Errors were encountered while processing
    ubuntu 安装 caffe 解决://home/xiaojie/anaconda/lib/libpng16.so.16:对‘inflateValidate@ZLIB_1.2.9’未定义的引用
    ubuntu安装caffe 解决:build_release/tools/caffe: error while loading shared libraries: libcudart.so.8.0: cannot open shar
    ubuntu 禁止内核更新
    ubutun 中notebook出现 Permission denied: Untitled.ipynb
    ubuntu下anaconda使用jupyter notebook加载tensorflow、pytorch
    ubuntu下用anaconda快速安装 pytorch
  • 原文地址:https://www.cnblogs.com/huanglei2010/p/9171809.html
Copyright © 2020-2023  润新知