从shell脚本调用JMX MBean方法 [英] Calling JMX MBean method from a shell script

查看:262
本文介绍了从shell脚本调用JMX MBean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何库允许我从shell脚本调用JMX MBean方法。我们通过JMX公开了一些操作/管理命令,我们可以让我们的管理员使用JConsole或VisualVM,但有些任务最好留给自动化。在那个自动化中,我们希望能够在运行的服务器上调用JMX MBean方法,最好是从shell脚本调用。

Are there any libraries that would allow me to call a JMX MBean method from a shell script. We expose some operations/admin commands through JMX, and we could have our admins use JConsole, or VisualVM, but some tasks are better left to automation. In that automation we'd like to be able to call a JMX MBean method on our running server, preferably from a shell script.

推荐答案

以下命令行JMX实用程序可用:

The following command line JMX utilities are available:


  1. jmxterm - 似乎是功能最齐全的实用程序。

  2. cmdline-jmxclient - 在WebArchive项目中使用似乎非常简单(自2006年以来没有开发它看起来像)

  3. Groovy脚本和JMX - 提供了一些非常强大的JMX功能,但需要groovy和其他库设置。

  4. JManage命令行
    功能
    - (缺点是
    它需要一个正在运行的JManage
    服务器来代理comm ands through)

  1. jmxterm - seems to be the most fully featured utility.
  2. cmdline-jmxclient - used in the WebArchive project seems very bare bones (and no development since 2006 it looks like)
  3. Groovy script and JMX - provides some really powerful JMX functionality but requires groovy and other library setup.
  4. JManage command line functionality - (downside is that it requires a running JManage server to proxy commands through)

Groovy JMX示例:

import java.lang.management.*
import javax.management.ObjectName
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl
import groovy.swing.SwingBuilder
import javax.swing.WindowConstants as WC

def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi'
String beanName = "com.webwars.gameplatform.data:type=udmdataloadsystem,id=0"
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection
def dataSystem = new GroovyMBean(server, beanName)

println "Connected to:\n$dataSystem\n"

println "Executing jmxForceRefresh()"
dataSystem.jmxForceRefresh();

cmdline-jmxclient示例:

如果你有一个


  • MBean:com.company.data:type = datasystem,id = 0

通过以下操作:


  • jmxForceRefresh()

然后你可以写一个简单的bash脚本(假设你下载 cmdline-jmxclient-0.10.3.jar 并放在与脚本相同的目录中):

Then you can write a simple bash script (assuming you download cmdline-jmxclient-0.10.3.jar and put in the same directory as your script):

#!/bin/bash

cmdLineJMXJar=./cmdline-jmxclient-0.10.3.jar
user=yourUser
password=yourPassword
jmxHost=localhost
port=9003

#No User and password so pass '-'
echo "Available Operations for com.company.data:type=datasystem,id=0"
java -jar ${cmdLineJMXJar} ${user}:${password} ${jmxHost}:${port} com.company.data:type=datasystem,id=0

echo "Executing XML update..."
java -jar ${cmdLineJMXJar} - ${jmxHost}:${port} com.company.data:type=datasystem,id=0 jmxForceRefresh

这篇关于从shell脚本调用JMX MBean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆