forked from springside/springside4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
springside#10 使用Jolokia 将JMX数据输出成Restful JSON数据, JMX重获新生。
- Loading branch information
1 parent
9856086
commit bc0bb68
Showing
20 changed files
with
174 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...es/showcase/src/main/java/org/springside/examples/showcase/jmx/ApplicationStatistics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.springside.examples.showcase.jmx; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.springframework.jmx.export.annotation.ManagedAttribute; | ||
import org.springframework.jmx.export.annotation.ManagedOperation; | ||
import org.springframework.jmx.export.annotation.ManagedResource; | ||
|
||
@ManagedResource(objectName = ApplicationStatistics.MBEAN_NAME, description = "Application Statistics Management Bean") | ||
public class ApplicationStatistics { | ||
|
||
public static final String MBEAN_NAME = "showcase:name=ApplicationStatistics"; | ||
|
||
private AtomicInteger listUserTimes = new AtomicInteger(); | ||
private AtomicInteger updateUserTimes = new AtomicInteger(); | ||
|
||
public void incrListUserTimes() { | ||
listUserTimes.incrementAndGet(); | ||
} | ||
|
||
public void incrUpdateUserTimes() { | ||
updateUserTimes.incrementAndGet(); | ||
} | ||
|
||
@ManagedAttribute(description = "Times of all users be listed") | ||
public int getListUserTimes() { | ||
return listUserTimes.get(); | ||
} | ||
|
||
@ManagedAttribute(description = "Times of users be updated") | ||
public int getUpdateUserTimes() { | ||
return updateUserTimes.get(); | ||
} | ||
|
||
@ManagedOperation(description = "Reset all statistics") | ||
public void resetStatistics() { | ||
listUserTimes.set(0); | ||
updateUserTimes.set(0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
examples/showcase/src/main/resources/log/applicationContext-log.xml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 27 additions & 8 deletions
35
examples/showcase/src/main/webapp/WEB-INF/views/story/jmx.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> | ||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | ||
<c:set var="baseUrl" value="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}"/> | ||
|
||
<html> | ||
<head> | ||
<title>JMX演示用例</title> | ||
<title>JMX演示用例</title> | ||
</head> | ||
|
||
<body> | ||
<h2>JMX演示用例</h2> | ||
|
||
<h4>技术说明:</h4> | ||
<h3>技术说明:</h3> | ||
<ul> | ||
<li>服务端演示使用Spring annotation定义MBean</li> | ||
<li>演示使用Spring annotation将POJO定义为MBean</li> | ||
<li>演示使用jolokia将JMX输出为Restul JSON Monitor API</li> | ||
</ul> | ||
|
||
<h4>用户故事:</h4> | ||
<div> | ||
使用JMX动态配置查看和配置Log4J日志等级。<br /> 客户端可使用JConsole或JManager, 远程进程URL为 localhost:2099 | ||
或完整版的service:jmx:rmi:///jndi/rmi://localhost:2099/jmxrmi | ||
</div> | ||
<h3>MBean介绍:</h3> | ||
<ul> | ||
<li>Log4j Mbean,控制Log4j的Logger Level, name为log4j:name=Log4j</li> | ||
<li>Application Statistics Mbean, 当用户在综合演示里查看/更新用户时,计数器将会递增, name为showcase:name=ApplicationStatistics</li> | ||
</ul> | ||
|
||
<h3>使用Jconsole或其他JMX客户端:</h3> | ||
<ul> | ||
<li>如果JConsole与应用在同一台机器,直接选择该进程。</li> | ||
<li>否则远程进程URL为 localhost:2099 或完整版的service:jmx:rmi:///jndi/rmi://localhost:2099/jmxrmi</li> | ||
</ul> | ||
|
||
<h3>与国际接轨的Resultful API:</h3> | ||
<ul> | ||
<li>获取所有统计信息: <a href="${baseUrl}/jolokia/read/showcase:name=ApplicationStatistics">${baseUrl}/jolokia/read/showcase:name=ApplicationStatistics</a></li> | ||
<li>获取展示用户列表次数: <a href="${baseUrl}/jolokia/read/showcase:name=ApplicationStatistics/ListUserTimes">${baseUrl}/jolokia/read/showcase:name=ApplicationStatistics/ListUserTimes</a></li> | ||
<li>获取重置清零统计信息: <a href="${baseUrl}/jolokia/exec/showcase:name=ApplicationStatistics/resetStatistics">${baseUrl}/jolokia/exec/showcase:name=ApplicationStatistics/resetStatistics</a></li> | ||
<li>获取showcase域下所有MBean的属性: <a href="${baseUrl}/jolokia/read/showcase:name=*">${baseUrl}/jolokia/read/showcase:name=*</a></li> | ||
<li>获取特定Logger的Level: <a href="${baseUrl}/jolokia/exec/log4j:name=Log4j/getLoggerLevel/org.springside">${baseUrl}/jolokia/exec/log4j:name=Log4j/getLoggerLevel/org.springside</a></li> | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.