Manage your web application with JMX

xiaoxiao2021-03-06  16

This is an article from TSS, with a simple example explains how to use JMX to manage your components in web applications.

http://www.theserverside.com/resources/article.jsp?l=jmxwebapps

Generally we use JMX to make your resources (which is some of the need to manage bean) to increase manageability, package the object you need to manage into MBean, then register into MBeanServer. Our management client calls the properties or operations exposed by MBeanServer to achieve the purpose of dynamic management components. Probably looked at this article, simply analyze the key in the following:

1. Look at the MBean code to implement Myjspstats, get MBeanServer through WebLogic JNDI service in the constructor and register yourself to MBeanServer. It uses the MBeanserver of the WebLogic server here, you can of course create your own MBeanServer, put it in the Application. Public class myjspstats imports myjspstatsmbean {

MBeanServer Server = null; // mbeanserver

INT Starts = 0; // Number Abandoned At Start Page Int Selects = 0; // Number Abandoned At Selection Int Confirms = 0; // Number Abandoned Before Confirmation Int Completions = 0; // Number of Completed User TX

Hashtable instart = new hashtable (); // track user tx started hashtable inselect = new has select hashtable inconfirm = new hashtable (); // track user tx in confirm

/ ** A no-argument constructor is necessary for Beans in JSPs ** / public MyJspStats () {try {Environment env = new Environment (); env.setProviderUrl ( "t3: // localhost: 7001"); env.setSecurityPrincipal ( "weblogic"); // username env.setSecurityCredentials ( "weblogic"); // password Context myCtx = env.getInitialContext (); MBeanHome mbeanHome = (MBeanHome) myCtx.lookup ( "weblogic.management.home.localhome") Server = mbeanhome.getmbeanserver ();

Objectname ObjName = new objectName (mbeanhome.getdomainName () ": name = myjspstats, type = myjspstats");

// register mbean so mabean can be subject.registermbean (this, objName);} catch (exception ex) {system.err.println ("Cannot get MBeanserver: ex);}} .... .

2. Look at the code of using Myjspstats below in JSP, create an object within the Application range using JSP's UseBean tags.

<% mbean.Updatetx (Request.GetSession (True), "Start");%>

Start a Transaction

Transfer Money Between Accounts

Abort Transaction

3. Below is a management page, on the management page, how to get MBeanServer, and call MBean management operations. MBeanhome mbeanhome = ("WebLogic.Management.home.localhome); MBeanServer Server = mbeanhome.getmbeanserver (); here acquire MBeanserver in the same way. Server.GetaTribute (ObjName, "Completions") This is the property of MBean.

<% @ Page import = "import javax.naming.Context; import javax.naming.InitialContext; import javax.management.ObjectName; import weblogic.jndi.Environment; import weblogic.management.MBeanHome; import javax.management.MBeanServer;" %>

User Transaction Statistics

User Transaction Stage Number of Transactions <% environment env = new environment (); env.setProviderURL ("T3: // localhost: 7001"); Env.setSecurityPrincipal ("WebLogic"); // UserName Env.setSecurityCredentials ("WebLogic"); //// password Context myCtx = new InitialContext (); MBeanHome mbeanHome = (MBeanHome) myCtx.lookup ( "weblogic.management.home.localhome"); MBeanServer server = mbeanHome.getMBeanServer (); ObjectName objName = new ObjectName (mbeanHome.getDomainName () ": Name = myjspstats, type = myjspstats");

Out.print ("

" server.getattribute (ObjName, "Completions") " "); out.print ("< Tr> Abandonded At Confirm Server.GetaTRibute (ObjName, "Confirms") " "); out.print ("
Abandonded At SELECT " Server.GetaTRibute (ObjName," Selects ") " "); out.print ("
Abandonded At Start " Server.getaTribute (ObjName," Starts ") " ");%>

转载请注明原文地址:https://www.9cbs.com/read-44236.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.036, SQL: 9