- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试启用我的核心 Java 应用程序以通过 JMX 进行远程访问。然而,两个限制使它变得比应该的更难。
a) 我无权更改在 Linux 机器上启动应用程序的脚本。因此,我无法将任何“jmxremote”参数传递给 jvm。
b) 我指定的远程端口 ( com.sun.management.jmxremote.port = xxxx
) 很可能没有打开,我无法修改脚本来尝试另一个打开的端口。我必须自动执行。
我试图通过编写一个类来绕过这些限制,该类将设置所有必需的 jmxremote 参数并找到一个“空闲”端口。
public class JmxRemoteConnectionHelper{
@Override
public void init( ) throws Exception{
InetAddress address = InetAddress.getLocalHost();
String ipAddress = address.getHostAddress();
String hostname = address.getHostName();
String port = String.valueOf( getFreePort( ) );
System.setProperty("java.rmi.server.hostname", ipAddress );
System.setProperty("com.sun.management.jmxremote", "true" );
System.setProperty("com.sun.management.jmxremote.authenticate", "false" );
System.setProperty("com.sun.management.jmxremote.ssl", "false" );
System.setProperty("com.sun.management.jmxremote.port", port );
}
private final int getFreePort( ){
**//seedPort is passed in the constructor**
int freePort = seedPort;
ServerSocket sSocket = null;
for( int i=ZERO; i<PORT_SCAN_COUNTER; i++ ){
try{
freePort = freePort + i;
sSocket = new ServerSocket( freePort );
//FOUND a free port.
break;
}catch( Exception e ){
//Log
}finally{
if( sSocket != null ){
try{
sSocket.close();
sSocket = null;
}catch(Exception e ){
//Log
}
}
}
}
return freePort;
}
}
如下图,我,然后通过spring初始化。
<bean id="JmxRemoteConnection" class="JmxRemoteConnectionHelper" init-method="init" />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" depends-on="JmxRemoteConnection" />
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false" >
<property name="assembler" ref="assembler"/>
<property name="namingStrategy" ref="namingStrategy"/>
<property name="autodetect" value="true"/>
<property name="server" ref="mbeanServer"/>
</bean>
<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource"/>
</bean>
<bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy" lazy-init="true">
<property name="attributeSource" ref="jmxAttributeSource"/>
</bean>
为了测试,我在我的 Windows 机器上启动了该应用程序。它正确启动。但是,当我在同一个盒子上启动 JConsole 并尝试通过“远程进程” (ip:port) 连接时,我得到一个“连接被拒绝” 底部的消息。
我怀疑 JMX 代理没有看到我正在设置的任何远程系统属性。
我正在使用 JDK 1.6。
最佳答案
由于您已经在使用 Spring,我认为您应该看看是否使用 ConnectorServerFactoryBean
可以做你想做的事。我从来不需要启动远程 JMX 服务器,但看起来这就是该对象可以为您做的事情。
关于java - 以编程方式启用远程 jmx 监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15560407/
我可以知道应用程序开发人员通常对使用 JMX 感兴趣的典型指标是什么,除了: CPU 使用率 内存消耗 尼古拉斯 最佳答案 我会补充: 类加载器行为 线程 关于jmx - 来自 JMX 的有趣指标,我
是否可以从命令行使用 JMX 在 linux (CentOS) 上运行的进程上获取服务器堆转储? 无法打开 VisualVM,无法安装jmap 最佳答案 可以用这个简单的代码来完成: import c
我必须根据数据库中的条目对 JMX 客户端进行身份验证。因此,我编写了一个自定义的 JMXAuthenticator 实现。 启动我的应用程序时,我可以通过“本地进程”使用 JConsole 访问 M
对于我即将发表的学士论文,我想开发一个工具,从 Apache Flink 收集系统和应用程序数据,并将这些数据以某种“事件”的形式发送到另一个系统。该工具将安装在 Flink 作业和任务管理器节点上。
我正在尝试将 jconsole 连接到通过以下方式调用的 jvm: java \ -Djava.util.logging.config.file=./logging.properties \ -Dco
在 JConsole 中查看 JMX bean 时,它将给定域部分下的所有 bean 呈现为层次结构。 (JVisualVM 与 JConsole MBeans 插件具有相同的行为。) 我意识到 JM
如何配置 CACTI 以监控来自 JMX 的值? 最佳答案 http://forums.cacti.net/post-197459.html有一个很好的教程,介绍如何设置 Cacti 以使用 jmx4
我正在尝试使用 jmx_exporter java 代理( https://github.com/prometheus/jmx_exporter )进行模式匹配和命名普罗米修斯指标。 关于如何在处理
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
看来我过去从来没有让这个工作过。目前,我知道它不起作用。 但是我们启动了 Java 进程: -Dcom.sun.management.jmxremote -Dcom.sun.management.jm
我想知道,我们有没有让开发更容易的框架/库?例如,Apache Mina 或 Netty 使 NIO 编程更容易。 听说过Spring JMX、MX4J,是不是很好用? 最佳答案 我为此使用了 Spr
我正在尝试编写一个应用程序监控工具,我遇到了两个标准,JPDA 和 JMX。他们似乎和我有些相似。有什么不同? 最佳答案 JPDA用于调试 和 JMX用于监控。如果您正在开发监控工具 - 选择是显而易
我已将 jmxtrans 配置为从 "kafka.server":type="BrokerTopicMetrics",name="AllTopicsMessagesInPerSec" 获取值 它有 3
所以我有一个运行 Apache Kafka(测试)的 EC2 服务器。它具有用于 JMX 和 EC2 安全设置的端口 9111,以打开该端口。 我试图在我的 Mac 上运行 JConsole 来读取该
如何将 JMX 指标发送到 statsD 守护进程?我可以看到有一些解决方案,其中有用于轮询 JMX 指标的插件,但我希望更多地将指标推送到一些守护进程,这些守护进程可以聚合并将其存储在某些存储中,例
我想在 tomcat7-maven-plugin 上启用 JMX。如何将 CATALINA_OPTS 传递给插件配置? 最佳答案 两种可能的解决方案(未测试): 在 MAVEN_OPTS 中添加 sy
有没有类似于 Spring JMX 导出器的东西 没有 使用 Spring 框架? SimpleJMX似乎是合理的,但似乎也是一个非常年轻的框架,只有一个人插入。 我需要将一大堆属性、方法和类公开为
我想提取这些数据http://code.google.com/p/memcached-session-manager/wiki/JMXStatistics通过 jmx 但仅使用命令行。 这是因为这是进
当我尝试运行我的应用程序时,出现上述错误。我确信这与我从 log4j 更新到 log4j2 有关,因为如果我不引用 log4j2.xml 文件,错误就会消失。 为什么我会收到此错误? 这是完整的堆栈跟
这与 JMS 和 JMS 提供者的情况类似吗?或者我可以在没有应用程序服务器和 JMX 提供程序的情况下使用 JMX 吗? 最佳答案 绝对是的。 JMX 是标准 JavaSE6 API 的一部分。每个
我是一名优秀的程序员,十分优秀!