読者です 読者をやめる 読者になる 読者になる

ぺーぺーSEのブログ

備忘録・メモ用サイト。

JMXコマンドラインツール(jmxterm)

Java JMX

JMXjavaプロセスにアクセスしたいけど、GUI環境無くてjconsole使えないってときに便利なOSSツール

■公式
http://wiki.cyclopsgroup.org/jmxterm/

jarファイル形式のツールで対話式でMBeanにアクセスできる。



■起動

C:\>java -jar jmxterm-1.0-alpha-4-uber.jar
Welcome to JMX terminal. Type "help" for available commands.
$>



■コマンド一覧表示(helpコマンド)

$>help
#following commands are available to use:
about    - Display about page
bean     - Display or set current selected MBean.
beans    - List available beans under a domain or all domains
bye      - Terminate console and exit
close    - Close current JMX connection
domain   - Display or set current selected domain.
domains  - List all available domain names
exit     - Terminate console and exit
get      - Get value of MBean attribute(s)
help     - Display available commands or usage of a command
info     - Display detail information about an MBean
jvms     - List all running local JVM processes
open     - Open JMX session or display current connection
option   - Set options for command session
quit     - Terminate console and exit
run      - Invoke an MBean operation
set      - Set value of an MBean attribute



JMXポートにアクセス(openコマンド)

$>open localhost:9999
#Connection to localhost:9999 is opened



ドメイン一覧表示(domainsコマンド)

$>domains
#following domains are available
Catalina
JMImplementation
Users
com.sun.management
java.lang
java.nio
java.util.logging
org.apache.derby
tomcat.jdbc



■MBean一覧表示(beansコマンド)※ここではCatalinaドメインに絞っている

$>beans -d Catalina
#domain = Catalina:
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/,j2eeType=Filter,name=Tomcat WebSocket (JSR356) Filter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/,j2eeType=Servlet,name=default
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/,j2eeType=Servlet,name=dispatcherServlet
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/,j2eeType=Servlet,name=jsp
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/,name=jsp,type=JspMonitor
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/docs,j2eeType=Filter,name=Tomcat WebSocket (JSR356) Filter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/docs,j2eeType=Servlet,name=default
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/docs,j2eeType=Servlet,name=jsp
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/docs,name=jsp,type=JspMonitor
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Filter,name=CompressionFilter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Filter,name=Request Dumper Filter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Filter,name=Set Character Encoding
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Filter,name=Timing Filter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Filter,name=Tomcat WebSocket (JSR356) Filter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=ChatServlet
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=CompressionFilterTestServlet
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=CookieExample
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=HelloWorldExample
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=RequestHeaderExample
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=RequestInfoExample
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=RequestParamExample
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=ServletToJsp
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=SessionExample
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=async0
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=async1
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=async2
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=async3
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=bytecounter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=default
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=jsp
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=numberwriter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,j2eeType=Servlet,name=stock
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/examples,name=jsp,type=JspMonitor
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,j2eeType=Filter,name=CSRF
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,j2eeType=Filter,name=SetCharacterEncoding
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,j2eeType=Filter,name=Tomcat WebSocket (JSR356) Filter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,j2eeType=Servlet,name=HTMLHostManager
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,j2eeType=Servlet,name=HostManager
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,j2eeType=Servlet,name=default
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,j2eeType=Servlet,name=jsp
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/host-manager,name=jsp,type=JspMonitor
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Filter,name=CSRF
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Filter,name=SetCharacterEncoding
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Filter,name=Tomcat WebSocket (JSR356) Filter
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Servlet,name=HTMLManager
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Servlet,name=JMXProxy
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Servlet,name=Manager
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Servlet,name=Status
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Servlet,name=default
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,j2eeType=Servlet,name=jsp
Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/manager,name=jsp,type=JspMonitor
Catalina:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/
Catalina:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/docs
Catalina:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/examples
Catalina:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/host-manager
Catalina:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/manager
Catalina:class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",resourcetype=Context,type=Resource
Catalina:class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",type=DataSource
Catalina:class=org.apache.catalina.UserDatabase,name="UserDatabase",resourcetype=Global,type=Resource
Catalina:context=/,host=localhost,name=Cache,type=WebResourceRoot
Catalina:context=/,host=localhost,name=NonLoginAuthenticator,type=Valve
Catalina:context=/,host=localhost,name=StandardContextValve,type=Valve
Catalina:context=/,host=localhost,type=Loader
Catalina:context=/,host=localhost,type=Manager
Catalina:context=/,host=localhost,type=NamingResources
Catalina:context=/,host=localhost,type=WebResourceRoot
Catalina:context=/,host=localhost,type=WebappClassLoader
Catalina:context=/docs,host=localhost,name=Cache,type=WebResourceRoot
Catalina:context=/docs,host=localhost,name=StandardContextValve,type=Valve
Catalina:context=/docs,host=localhost,type=Loader
Catalina:context=/docs,host=localhost,type=Manager
Catalina:context=/docs,host=localhost,type=NamingResources
Catalina:context=/docs,host=localhost,type=WebResourceRoot
Catalina:context=/docs,host=localhost,type=WebappClassLoader
Catalina:context=/examples,host=localhost,name=Cache,type=WebResourceRoot
Catalina:context=/examples,host=localhost,name=FormAuthenticator,type=Valve
Catalina:context=/examples,host=localhost,name=StandardContextValve,type=Valve
Catalina:context=/examples,host=localhost,name=foo/bar/name2,resourcetype=Context,type=Environment
Catalina:context=/examples,host=localhost,name=foo/name1,resourcetype=Context,type=Environment
Catalina:context=/examples,host=localhost,name=foo/name4,resourcetype=Context,type=Environment
Catalina:context=/examples,host=localhost,name=minExemptions,resourcetype=Context,type=Environment
Catalina:context=/examples,host=localhost,name=name3,resourcetype=Context,type=Environment
Catalina:context=/examples,host=localhost,type=Loader
Catalina:context=/examples,host=localhost,type=Manager
Catalina:context=/examples,host=localhost,type=NamingResources
Catalina:context=/examples,host=localhost,type=WebResourceRoot
Catalina:context=/examples,host=localhost,type=WebappClassLoader
Catalina:context=/host-manager,host=localhost,name=BasicAuthenticator,type=Valve
Catalina:context=/host-manager,host=localhost,name=Cache,type=WebResourceRoot
Catalina:context=/host-manager,host=localhost,name=StandardContextValve,type=Valve
Catalina:context=/host-manager,host=localhost,type=Loader
Catalina:context=/host-manager,host=localhost,type=Manager
Catalina:context=/host-manager,host=localhost,type=NamingResources
Catalina:context=/host-manager,host=localhost,type=WebResourceRoot
Catalina:context=/host-manager,host=localhost,type=WebappClassLoader
Catalina:context=/manager,host=localhost,name=BasicAuthenticator,type=Valve
Catalina:context=/manager,host=localhost,name=Cache,type=WebResourceRoot
Catalina:context=/manager,host=localhost,name=StandardContextValve,type=Valve
Catalina:context=/manager,host=localhost,type=Loader
Catalina:context=/manager,host=localhost,type=Manager
Catalina:context=/manager,host=localhost,type=NamingResources
Catalina:context=/manager,host=localhost,type=WebResourceRoot
Catalina:context=/manager,host=localhost,type=WebappClassLoader
Catalina:host=localhost,name=AccessLogValve,type=Valve
Catalina:host=localhost,name=ErrorReportValve,type=Valve
Catalina:host=localhost,name=StandardHostValve,type=Valve
Catalina:host=localhost,type=Deployer
Catalina:host=localhost,type=Host
Catalina:name="ajp-apr-8009",type=GlobalRequestProcessor
Catalina:name="ajp-apr-8009",type=ThreadPool
Catalina:name="http-apr-8080",type=GlobalRequestProcessor
Catalina:name="http-apr-8080",type=ThreadPool
Catalina:name=HttpRequest1,type=RequestProcessor,worker="http-apr-8080"
Catalina:name=StandardEngineValve,type=Valve
Catalina:port=8009,type=Connector
Catalina:port=8009,type=ProtocolHandler
Catalina:port=8080,type=Connector
Catalina:port=8080,type=ProtocolHandler
Catalina:realmPath=/realm0,type=Realm
Catalina:realmPath=/realm0/realm0,type=Realm
Catalina:type=Engine
Catalina:type=MBeanFactory
Catalina:type=Mapper
Catalina:type=NamingResources
Catalina:type=Server
Catalina:type=Service
Catalina:type=StringCache



■MBeanの情報を表示(infoコマンド)

$>info -b class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",resourcetype=Context,type=Reso
urce -d Catalina
#mbean = Catalina:class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",resourcetype=Context,t
ype=Resource
#class name = org.apache.catalina.mbeans.ContextResourceMBean
# attributes
  %0   - auth (java.lang.String, rw)
  %1   - description (java.lang.String, rw)
  %2   - modelerType (java.lang.String, r)
  %3   - name (java.lang.String, rw)
  %4   - scope (java.lang.String, rw)
  %5   - type (java.lang.String, rw)
#there's no operations
#there's no notifications

$>info -b class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",type=DataSource -d Catalina
#mbean = Catalina:class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",type=DataSource
#class name = org.apache.tomcat.util.modeler.BaseModelMBean
# attributes
  %0   - abandonWhenPercentageFull (java.lang.Integer, r)
  %1   - accessToUnderlyingConnectionAllowed (java.lang.Boolean, r)
  %2   - active (java.lang.Integer, r)
  %3   - alternateUsernameAllowed (java.lang.Boolean, r)
  %4   - className (java.lang.String, r)
  %5   - commitOnReturn (java.lang.Boolean, r)
  %6   - connectionProperties (java.lang.String, r)
  %7   - dataSource (javax.sql.DataSource, r)
  %8   - dataSourceJNDI (java.lang.String, r)
  %9   - defaultAutoCommit (java.lang.Boolean, r)
  %10  - defaultCatalog (java.lang.String, r)
  %11  - defaultReadOnly (java.lang.Boolean, r)
  %12  - defaultTransactionIsolation (java.lang.Integer, r)
  %13  - driverClassName (java.lang.String, r)
  %14  - fairQueue (java.lang.Boolean, r)
  %15  - idle (java.lang.Integer, r)
  %16  - ignoreExceptionOnPreLoad (java.lang.Boolean, r)
  %17  - initSQL (java.lang.String, r)
  %18  - initialSize (java.lang.Integer, r)
  %19  - jdbcInterceptors (java.lang.String, r)
  %20  - jmxEnabled (java.lang.Boolean, r)
  %21  - logAbandoned (java.lang.Boolean, r)
  %22  - logValidationErrors (java.lang.Boolean, r)
  %23  - loginTimeout (java.lang.Integer, r)
  %24  - maxActive (java.lang.Integer, r)
  %25  - maxAge (java.lang.Long, r)
  %26  - maxIdle (java.lang.Integer, r)
  %27  - maxWait (java.lang.Integer, r)
  %28  - minEvictableIdleTimeMillis (java.lang.Integer, r)
  %29  - minIdle (java.lang.Integer, r)
  %30  - modelerType (java.lang.String, r)
  %31  - name (java.lang.String, r)
  %32  - numActive (java.lang.Integer, r)
  %33  - numIdle (java.lang.Integer, r)
  %34  - numTestsPerEvictionRun (java.lang.Integer, r)
  %35  - password (java.lang.String, r)
  %36  - poolSweeperEnabled (java.lang.Boolean, r)
  %37  - propagateInterruptState (java.lang.Boolean, r)
  %38  - removeAbandoned (java.lang.Boolean, r)
  %39  - removeAbandonedTimeout (java.lang.Integer, r)
  %40  - rollbackOnReturn (java.lang.Boolean, r)
  %41  - size (java.lang.Integer, r)
  %42  - suspectTimeout (java.lang.Integer, r)
  %43  - testOnBorrow (java.lang.Boolean, r)
  %44  - testOnConnect (java.lang.Boolean, r)
  %45  - testOnReturn (java.lang.Boolean, r)
  %46  - testWhileIdle (java.lang.Boolean, r)
  %47  - timeBetweenEvictionRunsMillis (java.lang.Integer, r)
  %48  - url (java.lang.String, r)
  %49  - useDisposableConnectionFacade (java.lang.Boolean, r)
  %50  - useEquals (java.lang.Boolean, r)
  %51  - useLock (java.lang.Boolean, r)
  %52  - username (java.lang.String, r)
  %53  - validationInterval (java.lang.Long, r)
  %54  - validationQuery (java.lang.String, r)
  %55  - validationQueryTimeout (java.lang.Integer, r)
  %56  - validatorClassName (java.lang.String, r)
  %57  - waitCount (java.lang.Integer, r)
# operations
  %0   - void checkAbandoned()
  %1   - void checkIdle()
  %2   - void purge()
  %3   - void purgeOnReturn()
  %4   - void testIdle()
#there's no notifications



■MBeanから属性一覧を取得(getコマンド)

$>get -b class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",type=DataSource -d Catalina *
#mbean = Catalina:class=javax.sql.DataSource,context=/,host=localhost,name="jdbc/derby",type=DataSource:
connectionProperties = null;

propagateInterruptState = false;

useDisposableConnectionFacade = true;

defaultCatalog = null;

validationInterval = 30000;

jmxEnabled = true;

ignoreExceptionOnPreLoad = false;

logAbandoned = false;

commitOnReturn = false;

password = Password not available as DataSource/JMX operation.;

maxIdle = 0;

testWhileIdle = false;

removeAbandoned = false;

minIdle = 0;

abandonWhenPercentageFull = 0;

defaultReadOnly = null;

maxWait = 0;

active = 0;

size = 0;

logValidationErrors = false;

driverClassName = org.apache.derby.jdbc.EmbeddedDriver;

name = Tomcat Connection Pool[1-633127];

dataSource = null;

poolSweeperEnabled = true;

validationQueryTimeout = -1;

initSQL = null;

numActive = 0;

modelerType = org.apache.tomcat.jdbc.pool.DataSource;

validationQuery = null;

rollbackOnReturn = false;

className = org.apache.tomcat.jdbc.pool.DataSource;

numIdle = 0;

alternateUsernameAllowed = false;

dataSourceJNDI = null;

validatorClassName = null;

suspectTimeout = 0;

useEquals = true;

removeAbandonedTimeout = 60;

defaultAutoCommit = null;

loginTimeout = 0;

testOnConnect = false;

jdbcInterceptors = StatementCache(prepared=true,max=50);

idle = 0;

initialSize = 0;

defaultTransactionIsolation = -1;

url = jdbc:derby:H:/Derby/JpaSample;create=true;

numTestsPerEvictionRun = 0;

testOnBorrow = false;

fairQueue = true;

timeBetweenEvictionRunsMillis = 5000;

minEvictableIdleTimeMillis = 60000;

accessToUnderlyingConnectionAllowed = true;

maxAge = 0;

testOnReturn = false;

useLock = false;

waitCount = 0;

maxActive = 20;

username = null;

$>exit
#bye

いい感じ。

参考:
http://www.checksite.jp/jmxterm-command-line-tool/