`
scanfprintf123
  • 浏览: 80589 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

JMX Basic

阅读更多

1.What is JMX architecture?

   First, let's get a overview of the JMX architecture, it contains three layers as below: 
 

  • Instrumentation Layer: This layer only contains the manageable resources which might be property files or printer,fax device. Actually, no matter what the resources are, they are only applications,let's think about how we get access to these resources first, thro applicactions, isn't it?When we have this in common that the manageable resources are indeed applications, let's check what jmx can give us in this layer. In JMX's programmable world, this layer only contains two things: one is the MBean which is equal to the manageable resources,applications, the other is its corresponding MBean interface. As mentioned above, MBean is actually the original applictions, and its corresponding MBean interface is used to expose a set of manageable interface to the outside world, tell them what they can do on this manageable resources.
  • Agent Layer:Agent right here is like a container, the main thing in a agent is that, a MBeanServer, MBeanServer is used to hold the manageable resources, that is MBean. And besides that, agent layer also provide four typical services, they are timer service, dynamic loading manageable resources service, relationship service and the monitoring service, we will cover these four services later, but not here. Usually, agent used to be in the same machine with the manageable resources, what agent can do is providing a way to manage the resources.
  • Distributed Layer: After preparing the manageable resources and hold them in a MBeanServer,and then how can a client get access to them. Well, Distributed Layer will do things that would make agent layer availabel to the clients by adapter or connector, as the above picture shows. In brief,Distributed Layer is the outermost layer and make manageable resources accessible. It contains two types of interaction (as I said before, adaptor and connector), which allow client to connect to the agent layer.


2.Ready for our first example?

    In order to help you better understand the above concepts, I will show you an example to tie these three layers together,but before diving into this example, we need to visist a jmx friend first,  that is ObjectName, ObjectName is a naming system in jmx's world. It is just like the ID card in our world which is unique, it consists of two parts:
1.Domain Name: domain name is used to group the Mbeans register in a Mbean Server. Just for convinience, nothing else.
2.Key-Value pair: only provide descriptions for registered mbeans, such as ‘name=HelloWorld, this dont have to be the actual attribute the mbean has. And there is something we need to know is that this key-value pair will also be used to distinguish from other mbeans when their domain name is identical. 
   

 

Ok,now let's come to our example, I dont want  to use the common HelloWorld example, and here, I want to show you a more realistic example-the logging example.

 

Many of us have ever ran into this situation that is we got a problem on production environment and we can't reproduce it on development environment, and as we know, we can't get the enough log information from production environment due to its higher log level. In such a case, we need to change the log level to get enough log info, of cource, restarting the server is necessary. But as you know, it is almost impossible to restart the production server to trace problems like that. So, what can we do? Dont worry, JMX come to your rescue.

 

First,let's check our manageble resource,

public class LogManager implements LogManagerMBean{

	private static final String LOG_PATH = "log.properties";
	
	private static final String LOG_LEVEL="logLevel";
	
	private static final String DEBUG="debug";
	
	private static final String INFO="info";

	private final Properties content = new Properties();

	public LogManager() throws Exception {
		InputStream is = LogManager.class.getResourceAsStream(LOG_PATH);
		content.load(is);
	}
	
	public String getLogLevel()
	{
		return content.getProperty(LOG_LEVEL);
	}
	
	public void setLogLevel(String value)
	{
		content.setProperty(LOG_LEVEL, value);
	}
	
	public void printLogInfo()
	{
		String logLevel=getLogLevel();
		if(logLevel.equals(INFO))
			System.out.println("[info]: welcome jmx's world.");
		else if(logLevel.equals(DEBUG))
			System.out.println("[debug]: welcome jmx's world.");
		else
			System.out.println("[warn]: welcome jmx's world.");
	}
}



and then is our MBean interface, which determines what operations client can do on the manageable resource.

public interface LogManagerMBean {
	
	public void setLogLevel(String value);

	public void printLogInfo();
}



 From the above MBean interface, we can see that client can change the log level of logger on-the-fly.

 Note: printLogInfo() method only stimulate the usage of logger, since i dont want to introduce a complex example at your first glance of JMX application. 

  The last will be our agent:

public class Agent {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		//new a MBean server
		MBeanServer server=MBeanServerFactory.createMBeanServer("Hello");
		
		//new a manageable resource and register it in the server
		LogManagerMBean logManager=new LogManager();
		ObjectName logManagerName=new ObjectName("Hello:name=logManager");
		server.registerMBean(logManager, logManagerName);
		
		//new a adaptor and register it in the server
		HtmlAdaptorServer adaptor=new HtmlAdaptorServer();
		adaptor.setPort(8888);
		ObjectName adaptorName=new ObjectName("Hello:name=adaptor");
		server.registerMBean(adaptor, adaptorName);
		
		//start the adaptor
		adaptor.start();
	}

}



   The above are all codes we need, it is easy,isnt it? 

   When we done that, let's start our agent- java Agent, can connect to it thro our web browser(IE or FireFox etc) by using the url:

    http://localhost:8888 

   You can get a view like this: 

 
Before we change the log level, the log info would be like the following:


 
And then change the log level to 'debug':



Then let's check out the log info again:



Wow, we got it.



 

  • 大小: 112.5 KB
  • 大小: 16.9 KB
  • 大小: 2.5 KB
  • 大小: 665 Bytes
  • 大小: 609 Bytes
  • 大小: 939 Bytes
  • 大小: 3.7 KB
1
0
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    jmeter basic demo.jmx

    jmeter最基本的脚步编写,包含添加线程组,添加HTTP请求等

    truesightpulse-jmx-http:JMX HTTP接口

    - **安全策略**:为了防止未经授权的访问,JMX HTTP接口需要实施严格的认证和授权机制,比如使用Basic Auth或Digest Auth。 - **性能调优**:监控大量MBeans可能会对应用性能造成影响,因此,合理的采样频率和选择...

    core java basic

    在【工作经历】部分,邹志刚展示了他在实际项目中的应用能力,例如在DSP项目中使用JMX(Java Management Extensions)进行系统监控和管理,以及在SCAS项目中利用Java IO和多线程处理文件读写和备份。 【教育背景】...

    jolokia-extra-war-1.2.2.zip

    Jolokia提供了一个方便的接口来远程管理JMX服务,而"basic-maven-resolver"则提供了一个轻量级的解决方案,用于在资源有限的环境中解析和获取Maven依赖。对于Java开发者,理解和掌握这两个工具可以帮助优化开发流程...

    JBOSS使用指南

    也可以通过管理控制台或JMX接口进行远程部署。 ### 二、JBOSS的配置 #### 1. JBoss日志设置 配置日志主要涉及`logging.properties`文件,可以调整日志级别、格式和输出位置,以便收集和分析运行时的日志信息。 #...

    servo, Netflix应用监控库.zip

    servo, Netflix应用监控库 伺服:Java中的应用程序度量注意,观察,观察瑞典语。伺服提供了一个简单的接口,... 主要目标是::JMX是标准的监视接口,可以通过许多现有工具查询。保持简单的: 不需要编写大量代码( 如 M

    TongWeb5.0.1.1用户使用手册

    - **Web服务增强**: 改进了对Web服务的支持,包括SOAP、WS-I Basic Profile和WSDL等标准。 - **改进的事务管理**: 提供了更强大的事务管理功能,支持多种事务传播行为。 **1.3 TongWeb5.0的体系结构** TongWeb5.0...

    tomcat9.0.1

    8. **JMX(Java Management Extensions)**:JMX用于监控和管理应用程序,Tomcat提供了JMX支持,允许管理员通过JMX代理监控服务器状态和配置。 9. **错误处理和日志**:Tomcat提供了详细的错误页面和日志系统,帮助...

    ImportExport.rar

    最后,".pdb"文件(例如"BasicFormats.pdb"和"VSWebTestExport.pdb")是程序数据库文件,通常用于调试和符号解析。在本例中,它们可能包含关于导出插件的调试信息,对于开发者调试插件代码时是有用的,但对于普通...

    JmeterTemplates

    .JMX .CSV -- 如果您希望根据不同的可能性(例如国家与州)(超过 1 个州)进行一些测试,则可以进行数据文件设计。 这有助于参数化 csv 中的数据并链接到 Jmeter 测试计划,以使用有效负载运行不同的可能测试流。 ...

    JBOSS4.2 基本配置(全)

    6. **其他高级配置**:除了以上基础配置,JBOSS还支持日志管理、事务管理、集群部署、JMX监控等多种功能,其配置文件分布在`server/default/conf`和`server/default/deploy`目录下。例如,`logging.properties`用于...

    tomcat6服务器

    默认情况下,Tomcat不启用任何安全设置,需要手动配置`context.xml`或`web.xml`以实现HTTPS、Basic Auth等安全特性。 5. **性能优化**:Tomcat可以通过调整连接器配置、线程池大小、JVM内存分配等参数来优化性能。...

    Tomcat-6.0.35

    安全方面,Tomcat 6.0.35支持多种身份验证和授权机制,如Basic Auth、Form Auth以及digest auth。通过在`conf/tomcat-users.xml`文件中定义用户和角色,可以实现Web应用的访问控制。此外,还可以通过`Context`元素的...

    深入剖析Tomcat

    Tomcat提供了多种安全机制,如Basic Auth、Form Auth、Digest Auth等。源码分析可以帮助我们理解这些认证过程的实现细节,以及如何配置和扩展安全性。 八、session管理 Tomcat处理用户session的存储和复制,支持...

    《深入剖析Tomcat》的光盘源码

    7. **JMX(Java Management Extensions)**:Tomcat利用JMX提供管理和监控功能,允许用户通过JMX代理远程控制Tomcat,监控其运行状态。 8. **线程池与并发管理**:Tomcat通过Executor组件来管理线程池,优化并发...

    jboss-eap-4.3webconsole无法登录的解决方案

    <auth-method>BASIC <realm-name>ManagementRealm <role-name>JBossAdmin ``` - 确认`<role-name>`标签中的值为`JBossAdmin`,这是后续登录时所需的角色名称。 3. **配置用户名与密码文件**: - 在`...

    apache-tomcat-5.5.17-src

    │ ch12.rar FORM验证登录文件,BASIC验证配置文件,Realm配置代码 │ ch13.rar Tomcat阀的使用(实例演示) │ ch14.rar JDBC资源(实例演示) │ ch17.rar 将Tomcat嵌入到Java中(实例演示) │ ch19...

    XDoclet in Action

    - **Basic Usage**: Simple examples demonstrating how to use XDoclet tags and generate basic code snippets. - **Advanced Configuration**: Tips on customizing XDoclet configurations for specific project...

    jetty 事例

    - JMX支持:Jetty支持JMX(Java Management Extensions),可以通过JMX工具监控和管理Jetty实例。 - Admin Console:通过添加特定模块,可以启用Jetty的管理控制台,查看服务器状态、部署应用等。 8. **社区与...

Global site tag (gtag.js) - Google Analytics