English 中文(简体)
配置JMX 甲型六氯环己烷
原标题:Calling JMX MBean method from a shell script

是否有任何图书馆允许我用手稿打上JMX MBean方法。 我们通过JMX揭露了一些行动/行政指挥,我们的行政可以使用JConsole或视觉控制器,但有些任务最好留给自动化处理。 在这种自动化中,我们想能够在我们的运行服务器上使用一种JMX MBean方法,最好是用手稿。

最佳回答

具备以下指挥线JMX公用事业:

  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)

www.un.org/Depts/DGACM/index_spanish.htm Groovy JMX Example:

import java.lang.management.*
import javax.management.ObjectName
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl

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:
$dataSystem
"

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

<<>strong>cmdline-jmxclient example:

如果有

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

行动:

  • jmxForceRefresh()

然后,你可以写一个简单的印本(假设你下载cmdline-jmxclient-0.10.3.jar。 并列入与你的文字相同的目录:

#!/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
问题回答

I ve开发了jmxfuse,暴露了JMX Mbeans作为CFCUSE文档系统,其功能与/proc f相似。 它依靠Jolokia作为通往JMX的桥梁。 供款和业务可读写。

http://code.google.com/p/jmxfuse/"rel=“nofollow noreferer”>http://code.google.com/p/jmxfuse/

例如,改为:

me@oddjob:jmx$ cd log4j/root/attributes
me@oddjob:jmx$ cat priority

a. 说明:

me@oddjob:jmx$ echo "WARN" > priority

援引一项行动:

me@oddjob:jmx$ cd Catalina/none/none/WebModule/localhost/helloworld/operations/addParameter
me@oddjob:jmx$ echo "myParam myValue" > invoke

Syabru Nagios JMX plugin 意在从Nagios处使用,但确实需要Nagios,而且非常方便地用于指挥线:

~$ ./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:1099/JMXConnector --username myuser --password mypass -O java.lang:type=Memory -A HeapMemoryUsage -K used 
JMX OK - HeapMemoryUsage.used = 445012360 |  HeapMemoryUsage used =445012360;;;;

可能最容易在 Java撰写。

import javax.management.*;
import javax.management.remote.*;

public class JmxInvoke {

    public static void main(String... args) throws Exception {
        JMXConnectorFactory.connect(new JMXServiceURL(args[0]))
            .getMBeanServerConnection().invoke(new ObjectName(args[1]), args[2], new Object[]{}, new String[]{});    
    }

}

这将汇编成单层,不需要服务器或任何复杂的装配。

会 议

javac JmxInvoke.java
java -cp . JmxInvoke [url] [beanName] [method]

风险不大,但你可以操作一种带有从JMX console、URL和http://www.un.org/Depts/dp.pdf中得出的价值(如果需要的话):

curl -s -X POST --user  myuser:mypass 
  --data "action=invokeOp&name=App:service=ThisServiceOp&methodIndex=3&arg0=value1&arg1=value1&submit=Invoke"
  http://yourhost.domain.com/jmx-console/HtmlAdaptor

Beware: 方法指数可能会随着软件的变化而变化。 而网络形式的实施也会发生变化。

以上是数据交换服务网页的来源。

http://yourhost.domain.com/jmx-console/HtmlAdaptor?action=inspectMBean&name=YourJMXServiceName

表格来源:

form method="post" action="HtmlAdaptor">
   <input type="hidden" name="action" value="invokeOp">
   <input type="hidden" name="name" value="App:service=ThisServiceOp">
   <input type="hidden" name="methodIndex" value="3">
   <hr align= left  width= 80 >
   <h4>void ThisOperation()</h4>
   <p>Operation exposed for management</p>
    <table cellspacing="2" cellpadding="2" border="1">
        <tr class="OperationHeader">
            <th>Param</th>
            <th>ParamType</th>
            <th>ParamValue</th>
            <th>ParamDescription</th>
        </tr>
        <tr>
            <td>p1</td>
           <td>java.lang.String</td>
         <td> 
            <input type="text" name="arg0">
         </td>
         <td>(no description)</td>
        </tr>
        <tr>
            <td>p2</td>
           <td>arg1Type</td>
         <td> 
            <input type="text" name="arg1">
         </td>
         <td>(no description)</td>
        </tr>
    </table>
    <input type="submit" value="Invoke">
</form>

http://www.jmx4perl.org“rel=“nofollow noreferer”>jmx4perl。 它为远洋的Java E服务器的甲基溴提供无缝通道。 然而,需要在目标平台上安装一个小型代理服务器,该平台通过吉斯人有效载荷的吉卜赛人空中交通管制处提供其余的JMX准入。 (0.50欧元通过采用JSR-160代理方式增加无代理模式。)

较之当地启动 j和轻松使用,优势是快速启动时间。 jmx4perl有一整套可轻易用在您自己的文字上的每个模块:

use JMX::Jmx4Perl;
use JMX::Jmx4Perl::Alias;   # Import certains aliases for MBeans

print "Memory Used: ",
      JMX::Jmx4Perl
          ->new(url => "http://localhost:8080/j4p")
          ->get_attribute(MEMORY_HEAP_USED);

You can also use alias for common MBean/Attribute/Operation combos (e.g. for most MXBeans). For additional features (Nagios-Plugin, XPath-like access to complex attribute types, ...), please refer to the documentation of jmx4perl.

查阅JManage。 它能够执行甲基溴方法,并从command Line 获取/。

@Dougnukem回答帮助我做了很多工作。 我采用了格罗维尼办法(采用2.3.3格罗夫办法)。

I did some changes on Dougnukem code. This will work with Java 7 and will print two attributes to stdout every 10 sec.

        package com.my.company.jmx
        import groovy.util.GroovyMBean;
        import javax.management.remote.JMXServiceURL
        import javax.management.remote.JMXConnectorFactory
        import java.lang.management.*

            class Monitor {
                static main(args) {
                    def serverUrl =  service:jmx:rmi:///jndi/rmi://localhost:5019/jmxrmi 
                    String beanName = "Catalina:type=DataSource,class=javax.sql.DataSource,name="jdbc/CommonDB""
                    println  "numIdle,numActive"

                    while(1){
                        def server = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl))
                       //make sure to reconnect in case the jvm was restrated 
                        server.connect()
                        GroovyMBean mbean = new GroovyMBean(server.MBeanServerConnection, beanName)
                        println  "${mbean.numIdle},${mbean.numActive}"
                        server.close()
                        sleep(10000)
                    }

                }
            }

Compile this code into a jar using maven-compiler-plugin so you will not require groovy installation only the groovy-all.jar . Below is the relevant plugin definition and dependency.

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerId>groovy-eclipse-compiler</compilerId>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>2.8.0-01</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-batch</artifactId>
                        <version>2.3.4-01</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.3</version>
        </dependency>
    </dependencies>

用批量或批量进行校对,并将印刷数据,以便停用。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签