`
yunzhu
  • 浏览: 1140864 次
  • 性别: Icon_minigender_1
  • 来自: 南京
博客专栏
B2b19957-cda7-3a9e-83a0-418743feb0ca
监控应用服务器
浏览量:109057
2e8be8be-e51f-346c-bcdd-12623c9aa820
Web前端开发
浏览量:119228
Bfa5df64-a623-34b9-85b8-ef3ce2aed758
经典异常的解决
浏览量:203957
社区版块
存档分类
最新评论

监控WebLogic 9.x和10.x解决方案(监控应用服务器系列文章)

阅读更多

前言:做了一个监控应用服务器的项目(支持Tocmat、WebSphere、WebLogic各版本), 过程也算是磕磕绊绊,由于网上缺少相关资料,或者深陷于知识的海洋难以寻觅到有效的资料,因而走过不少弯路,遇过不少困难。为了留下点印记,给后来人留下 点经验之谈,助之少走弯路,故将这些经验整理出来,与大家分享。水平有限,难免疏漏,还望指正。如有疑问,欢迎留言,或者加入Q群参与讨 论:35526521

 

 

其实学习一项新的技术,刚开始最困难就是难以找到有效的资料,OK,首先分享几个官方文档的地址:

 

几个重要的官方文档地址

——相当于葵花宝典的功效(放心,不需自宫)

 

一、使用 JMX 开发自定义管理实用工具

http://www.oraclefmw.com/wls92/jmx/index.html

这是针对WebLogic 9.2的中文版,第一好东西,里面不仅讲解有原理讲解,还有Demo和教程

 

二、使用JMX访问WebLogic Server MBean的Demo和教程

● WebLogic 9.x:

http://download.oracle.com/docs/cd/E13222_01/wls/docs90/jmx/accessWLS.html

● WebLogic 10.x:

http://download.oracle.com/docs/cd/E11035_01/wls100/jmx/accessWLS.html

 

三、WebLogic的MBean参考手册

http://download.oracle.com/docs/cd/E14571_01/apirefs.1111/e13951/core/index.html

有了MBean参考手册,想要监控什么指标,直接到里面找,纯粹是体力活,剩下的就是考虑怎么把代码写得简单可用(Clean code that works )了

 

只要有了这几个地址,开发监控WebLogic 9.x和10.x的项目就变得简单了。想当年,我就是在找资料上花费了大把大把的时间,而且那绝对是相当的痛苦。如果你不是第一时间看到了这篇文章,相信你一定感同身受吧!但是恭喜你,现在你不用那么痛苦了,哈哈,开个玩笑……

 

 

访问WebLogic使用的JAR包

访问WebLogic 9.x所使用的JAR包:

wlclient.jar、wljmxclient.jar

在%WL_HOME%\server\lib目录下

 

访问WebLogic 10.x所使用的JAR包:

由于10.x的API有变化,必须使用JarBuilder Tool生成wlfullclient.jar,具体参见官方的教程,上面的“葵花宝典”里面有链接。

 

监控所依赖的JAR包的存放位置

 

我们会通过这种方式获取和MBean Server的连接:

------------------------------------------------------------------------------------------------------------------------------

JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);

------------------------------------------------------------------------------------------------------------------------------

 

代码在Eclipse下通过Java程序调用没有任何问题,作为Web应用部署到Tocmat就出问题了,会报如下异常:

------------------------------------------------------------------------------------------------------------------------------

Unsupported protocol: t3

------------------------------------------------------------------------------------------------------------------------------

 

具体原因如下(这是找了很久以后在一个国外的论坛上看到的):

------------------------------------------------------------------------------------------------------------------------------

Here's the issue that I'm facing:
To get a JMX connection using JMXConnectionFactory using below: JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
I have to rely on classes in weblogic.jar
That is because the implementation of JMXConnector is in weblogic.jar. However, the interface/abstract class for JMXConnectionFactory lives in rt.jar that comes with JDK1.5 or JDK1.6.
Because rt.jar is (probably) used by the bootstrap classloader, I HAVE to include weblogic.jar in the CATALINA_HOME/common/lib directory. If I do so, I can get the JMX part of the solution to work because both, rt.jar and weblogic.jar are loaded by the same (system) classloader.

------------------------------------------------------------------------------------------------------------------------------

 

解决办法很简单: 将wlfullclient.jar放到Tomcat安装目录下的lib目录下即可。

------------------------------------------------------------------------------------------------------------------------------

刚发现这个问题时很是诧异,始终想不通,后来在老外的一个论坛上找到类似问题,原来, JMXConnector接口是在JDK1.5/JDK1.6的rt.jar里面,而具体实现是在wlfullclient.jar里面。问题就在这里, rt.jar是由系统类加载器加载的, wlfullclient.jar如果放在自己的WEB-INFO/lib目录下,就是由WebappClassLoader去加载了。所以我们将wlfullclient.jar放到Tomcat安装目录下的lib目录下,这样wlfullclient.jar跟rt.jar就是由同一个classloader加载的了,所以问题就迎刃而解了。

------------------------------------------------------------------------------------------------------------------------------

 

 

一个Demo:采集Web应用的Servlet信息

public class MonitorServlets {
	private static MBeanServerConnection connection;
	private static JMXConnector connector;
	private static final ObjectName service;

	// Initializing the object name for DomainRuntimeServiceMBean
	// so it can be used throughout the class.
	static {
		try {
			service = new ObjectName(
					"com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
		} catch (MalformedObjectNameException e) {
			throw new AssertionError(e.getMessage());
		}
	}

	/**
	 * 测试本地的WebLogic10.3
	 */
	public static void main1(String[] args) throws Exception {
		String hostname = "localhost";
		String portString = "7001";
		String username = "weblogic";
		String password = "weblogic123";
		MonitorServlets monitor = new MonitorServlets();
		initConnection(hostname, portString, username, password);
		monitor.getServletData();
		connector.close();
	}

	/**
	 * 测试192.168.1.5服务器上的WebLogic9.2
	 */
	public static void main(String[] args) throws Exception {
		String hostname = "192.168.1.5";
		String portString = "7001";
		String username = "weblogic";
		String password = "weblogic";
		MonitorServlets monitor = new MonitorServlets();
		initConnection(hostname, portString, username, password);
		monitor.getServletData();
		connector.close();
	}

	/**
	 * Initialize connection to the Domain Runtime MBean Server
	 * 
	 * @param hostname
	 * @param portString
	 * @param username
	 * @param password
	 * @throws IOException
	 * @throws MalformedURLException
	 */
	public static void initConnection(String hostname, String portString,
			String username, String password) throws IOException,
			MalformedURLException {
		String protocol = "t3";
		Integer portInteger = Integer.valueOf(portString);
		int port = portInteger.intValue();
		String jndiroot = "/jndi/";
		String mserver = "weblogic.management.mbeanservers.domainruntime";
		JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,
				jndiroot + mserver);
		Hashtable<String, String> h = new Hashtable<String, String>();
		h.put(Context.SECURITY_PRINCIPAL, username);
		h.put(Context.SECURITY_CREDENTIALS, password);
		h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
				"weblogic.management.remote");
		connector = JMXConnectorFactory.connect(serviceURL, h);
		connection = connector.getMBeanServerConnection();
	}

	/**
	 * Get an array of ServerRuntimeMBeans
	 * 
	 * @return
	 * @throws Exception
	 */
	public static ObjectName[] getServerRuntimes() throws Exception {
		return (ObjectName[]) connection
				.getAttribute(service, "ServerRuntimes");
	}

	/**
	 * Get an array of WebApplicationComponentRuntimeMBeans
	 * 
	 * @throws Exception
	 */
	public void getServletData() throws Exception {
		ObjectName[] serverRT = getServerRuntimes();
		int length = (int) serverRT.length;
		for (int i = 0; i < length; i++) {
			System.out
					.println("===========================================ServerRuntimes");
			String name = (String) connection.getAttribute(serverRT[i], "Name");
			String state = (String) connection.getAttribute(serverRT[i],
					"State");
			System.out.println("Server name: " + name + ".Server state: "
					+ state);

			ObjectName[] appRT = (ObjectName[]) connection.getAttribute(
					serverRT[i], "ApplicationRuntimes");
			int appLength = (int) appRT.length;
			for (int x = 0; x < appLength; x++) {
				System.out
						.println("-------------------------------------------ApplicationRuntimes");
				System.out.println("Application name: "
						+ (String) connection.getAttribute(appRT[x], "Name"));

				ObjectName[] compRT = (ObjectName[]) connection.getAttribute(
						appRT[x], "ComponentRuntimes");
				int compLength = (int) compRT.length;
				for (int y = 0; y < compLength; y++) {
					String componentName = (String) connection.getAttribute(
							compRT[y], "Name");
					String componentType = (String) connection.getAttribute(
							compRT[y], "Type");
					System.out.println("  Component name: " + componentName
							+ " , Component type: " + componentType);

					if (componentType.toString().equals(
							"WebAppComponentRuntime")) {
						ObjectName[] servletRTs = (ObjectName[]) connection
								.getAttribute(compRT[y], "Servlets");
						int servletLength = (int) servletRTs.length;
						for (int z = 0; z < servletLength; z++) {
							System.out.println("    Servlet name: "
									+ (String) connection.getAttribute(
											servletRTs[z], "Name"));
							System.out.println("       Servlet context path: "
									+ (String) connection.getAttribute(
											servletRTs[z], "ContextPath"));
							System.out
									.println("       Invocation Total Count : "
											+ (Object) connection.getAttribute(
													servletRTs[z],
													"InvocationTotalCount"));
						}
					}
				}
			}
		}
	}

}

 

分享到:
评论
1 楼 yunzhu 2015-01-23  
WebLogic的MBean参考手册

原来这个网址已经失效:
http://download.oracle.com/docs/cd/E14571_01/apirefs.1111/e13951/core/index.html

这是最新的网址:
http://docs.oracle.com/cd/E13222_01/wls/docs90/wlsmbeanref/core/index.html

相关推荐

    使用sitescope监控weblogic服务

    Mercyry SiteScope是一款无代理监测解决方案,可确保分布式IT基础架构——如服务器、操作系统、网络设备、网络服务、应用和应用组件的可用性和性能。这款主动的、基于Web界面的基础架构监测解决方案是非常简洁的,...

    springboot参考指南

    67.10. 将Spring Data仓库暴露为REST端点 vii. 68. 数据库初始化 i. 68.1. 使用JPA初始化数据库 ii. 68.2. 使用Hibernate初始化数据库 iii. 68.3. 使用Spring JDBC初始化数据库 iv. 68.4. 初始化Spring Batch数据库...

    电信系统BMC方案建议书

    • BMC系统监控解决方案设计目标 6 • BMC监控解决方案设计方法 8 2.1.1 BMC PATROL体系结构 9 • BMC管理解决方案实现的功能 9 2.1.2 管理平台 9 2.1.3 运行统计报告 10 2.1.4 操作系统管理 10 2.1.5 Oracle数据库...

    Loadrunner报错日志

    1、首先检查是不是连接weblogic服务过大部分被拒绝,需要监控weblogic的连接等待情况,此时需要增加acceptBacklog,每次增加25%来提高看是否解决,同时还需要增加连接池和调整执行线程数,(连接池数*Statement ...

    超级有影响力霸气的Java面试题大全文档

    多态性语言具有灵活、抽象、行为共享、代码共享的优势,很好的解决了应用程序函数同名问题。 5、String是最基本的数据类型吗?  基本数据类型包括byte、int、char、long、float、double、boolean和short。  java....

    基于SSHI架构的开发平台技术方案

    采用标准的J2EE规范,支持全部流行的商业应用服务器和其它Web容器比如:WebSphere、WebLogic、Tomcat、Jboss、等 注释配置采用JSR-250 规范定义的注释标记 支持流行的关系型数据库:Oracle、Db2、MySQL 等 提供CXF ...

    java 面试题 总结

    多态性语言具有灵活、抽象、行为共享、代码共享的优势,很好的解决了应用程序函数同名问题。 2、String是最基本的数据类型吗? 基本数据类型包括byte、int、char、long、float、double、boolean和short。 java.lang....

    Java数据编程指南

    软件、对象、数据设计与建模 第1章 软件开发的方法与过程 为什么我们需要方法与过程 什么是软件方法与过程 方法的内容 过程模型 源代码管理的要素 软件缺陷与修改的跟踪和解决方案 软件品质...

    soa_rest_api:适用于 Oracle SOA Suite 的 REST API - 用 JRuby 编写并使用 Rails

    JMX 是用于监视和管理网络资源的 J2EE 解决方案。 与 SNMP 和其他管理标准一样,JMX 是一个公共规范,许多常用监控产品的供应商都支持它。 WebLogic Server 提供了一组 MBean,可用于通过 JMX 配置、监视和管理 ...

    JAVA上百实例源码以及开源项目

     Java绘制图片火焰效果,源代码相关注释:前景和背景Image对象、Applet和绘制火焰的效果的Image对象、Applet和绘制火焰的效果的Graphics对象、火焰效果的线程、Applet的高度,图片到图片装载器、绘制火焰效果的X坐标...

    JAVA上百实例源码以及开源项目源代码

     Java绘制图片火焰效果,源代码相关注释:前景和背景Image对象、Applet和绘制火焰的效果的Image对象、Applet和绘制火焰的效果的Graphics对象、火焰效果的线程、Applet的高度,图片到图片装载器、绘制火焰效果的X坐标...

Global site tag (gtag.js) - Google Analytics