`
kylinsoong
  • 浏览: 236128 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JMX Architecture & "Hello Word" the JMX way

阅读更多

JMX Architecture Overview:

JMX technology provides a standard API for management and monitoring of resources. As http://kylinsoong.iteye.com/admin/blogs/794995  Part 3 depicted, the JMX architecture can be broken down into three levels: Instrumentation, Agent, Remote Management, As the following figure described:

      Instrumentation Layer contains MBeans representing their manageable resources, such as applications, devices, or services, are instrumented using Java objects called Managed Beans (MBeans). MBeans expose their management interfaces, composed of attributes and operations, through a JMX agent for remote management and monitoring;

      Agent Layer is the main component of a JMX agent is the MBean server. This is a core managed object server in which MBeans are registered. A JMX agent also includes a set of services for handling MBeans. JMX agents directly control resources and make them available to remote management agents;

      Distributed Layer also named Remote Management layer, contain adapters and connectors make a JMX agent accessible from remote management applications outside the agent’s Java Virtual Machine (Java VM).

 

HelloWorld JMX way

1. Complete Instrumentation layer dev

      The first step in developing the HelloWorld MBean is to write its Java interface. The interface declares three methods: one getter, one setter, and an additional method for printing the HelloWorld MBean’s greeting. Code view:

public interface HelloWorldMBean {
	public void setGreeting( String greeting );
	public String getGreeting();
	public void printGreeting();
}

 Before we start HelloWroldMBean implemetation, we introduce JMX notification first, notification  is the most imprtant feature of JMX, any managment system need notification mechanism, to add notification to our Helloworld mbean we need to extends the avax.management.NotificationBroadcasterSupport. Our MBean class:

public class HelloWorld extends NotificationBroadcasterSupport implements HelloWorldMBean {
	
	private String greeting = null;

	public HelloWorld() {
		this.greeting = "Hello World! I am a Standard MBean";
	}

	public HelloWorld(String greeting) {
		this.greeting = greeting;
	}

	public void setGreeting(String greeting) {
		this.greeting = greeting;
		Notification notification = new Notification("jmx.demo.helloWorld.test"
													, this
													, -1
													, System.currentTimeMillis()
													, greeting );
		sendNotification(notification);
	}

	public String getGreeting() {
		return greeting;
	}

	public void printGreeting() {
		System.out.println(greeting);
	}
}

2 Complete Agent Code

      As step 1, we have our HelloWorldMbean, we need to make it available to use, to do so we must register it in a JMX Agent. Therefore we create HelloAgent class JMX agents are JMX components in the agent layer of JMX and are the containers for MBeans. The HelloAgent class performs 4 important tasks:

      1> It creates an MBeanServer instance to contain MBeans.

      2> It creates an HTML adapter to handle connections from HTML clients.

      3> It registers a new instance of the HelloWorld MBean.

      4> It handles the notification that HelloWorldMBean sent.

public class HelloAgent implements NotificationListener {

	private MBeanServer mbs = null;
	
	public HelloAgent() {
//		mbs = MBeanServerFactory.createMBeanServer("jmx.demo.HelloAgent");
		mbs = ManagementFactory.getPlatformMBeanServer();
		
		HtmlAdaptorServer adapter = new HtmlAdaptorServer();
		
		HelloWorld hw = new HelloWorld();
		
		ObjectName adapterName = null;
		ObjectName helloWorldName = null;
		
		try {
			helloWorldName = new ObjectName( "jmx.demo.HelloAgent:type=helloWorld,name=helloWorld" );
			mbs.registerMBean( hw, helloWorldName );
			hw.addNotificationListener(this, null, null);
			
			adapterName = new ObjectName("jmx.demo.HelloAgent:type=htmlAdapter,name=htmlAdapter,port=8000");
			adapter.setPort(8000);
			mbs.registerMBean( adapter, adapterName );
			adapter.start();
		}  catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String args[]) throws InterruptedException {
		System.out.println("HelloAgent is running");
		HelloAgent agent = new HelloAgent();
		Thread.sleep(Long.MAX_VALUE);
	}

	public void handleNotification(Notification notification, Object handback) {
		System.out.println( "Receiving notification..." );
		System.out.println( notification.getType() );
		System.out.println( notification.getMessage() );
	}
}

 3. Compete Distibuted layer Code

      In this simple HelloWorld example we only Use  HTML adapter to implement remote management, however, RMI connector implement remote management is more popular, I will explore into it in the later blogs. In this blog we will show Html adapter implement remote management in Test section.

 

HelloWorld Test

      After starting the main method, we can through 2 methods test and manage HelloWrold

Method one:

      Start a new command line, input 'jconsole' the following widget came out:



 Clicking HelloAgent then you will get into Jconsole control interface and find both HelloWorld and htmlAdapter selection folder bar in the left menu tree:



 Clicking reference method or change the attributes, the corresponding action will take place.

Method two:

      Through http://127.0.0.1:8000/ we could find jmx.demo.HelloAgent from All Agent View List 



 Cliking helloWord we also can find the operation and attributes, through HTML interface we also can triger the response notification event.



 

  • 大小: 23.8 KB
  • 大小: 21.7 KB
  • 大小: 15.5 KB
  • 大小: 2.5 KB
0
0
分享到:
评论
2 楼 kylinsoong 2011-10-27  
up2pu 写道
http://kylinsoong.iteye.com/admin/blogs/794995
This cannot be accessed by other users.

try use this:http://kylinsoong.iteye.com/blog/794995
1 楼 up2pu 2011-10-26  
http://kylinsoong.iteye.com/admin/blogs/794995
This cannot be accessed by other users.

相关推荐

    JMX HelloWorld Download

    NULL 博文链接:https://hintcnuie.iteye.com/blog/255815

    jmx_access&password;

    此资源是用于开发人员或者测试人员在使用java mission control时,需要放置在Tomcat中的文件

    JMX实战 JMX开发

    JMX实战 书中不仅有对于基础知识的介绍,还有对于JMX开发中重大的体系架构问题的深入探讨,总结了大量JMX开发中的设计模式,并讨论了框架、安全性与性能等等。书中提供了几个典型的例子,兼顾各种开发平台,这些...

    jmx一步步来 jmx快速上手指南

    jmx快速上手 jmx快速上手 jmx快速上手 jmx快速上手

    亲测可用 com.sun.jmx. jmxri-1.2.1.jar

    Description Resource Path Location Type Missing artifact com.sun.jmx:jmxri:jar:1.2.1 pom.xml /eshop-storm line 2 Maven Dependency Problem

    Fiddler导出jmx文件

    Fiddler导出jmx文件,解决Fiddler导出文件中 没有jmx文件选项,各个版本fiddler都适用

    jmx入门

    为什么JMX那么受欢迎,JMX到底有那些优势只得人们去学习和理解,本文从JMX的基本架构、hellowold jmx以及spring对JMX的支持讲起,希望大家能通过本文对JMX有个基础的认识,并能通过本文为今后学习JMX打个基础

    jmx监控tomcat测试包

    catalina-jmx-remote.jar放到tomcat/lib目录下 如果是windows版本,编辑TOMCAT_HOME/bin/catalina.bat,在开头加入下面几行: set CATALINA_OPTS=%CATALINA_OPTS% -Djava.rmi.server.hostname=JMX_HOST set CATALINA...

    Hbase和Hadoop JMX监控实战

    Hbase和Hadoop JMX监控实战

    JMX小例子以及介绍

    JMX小例子以及介绍 JMX小例子以及介绍 JMX小例子以及介绍

    JMX与JMS的概念

    JMX与JMS的概念

    jmx-jvm配置

    jmx配置

    jmx监控activeMQ监控

    activeMQ开启jmx固定rmi端口,穿透防火墙,用了一天的时间,踩了无数的坑,拿出来共享.

    JBoss JMX实现架构

    JBoss JMX实现架构 JBoss JMX实现架构

    JMX一步一步来,快速学会开发JMX应用

    JMX一步一步来,从最基本的应用开始入手,快速应用开发。

    jmx监控weblogic,tomcat,websphere源码

    java项目,自己做的项目利用jmx监控weblogic,tomcat,websphere源码

    jmx介绍和使用

    jmx的简单介绍和使用,包含一些简单的代码示例,看完基本能了解jmx并使用。

    Jmx实例demo下载

    java实现Jmx实例,jmxdemo项目源码下载

    Zabbix通过JMX方式监控java中间件

    Zabbix通过JMX方式监控java中间件 Zabbix2.0添加了支持用于监控JMX应用程序的服务进程,称为“Zabbix-Java-gateway”;它是用java写的一个程序。 工作原理: zabbix_server想知道一台主机上的特定的JMX值时,它向...

Global site tag (gtag.js) - Google Analytics