JMX support for Clojure
Usage (require '[clojure.java.jmx :as jmx])
What beans do I have?
(jmx/mbean-names ":") -> #<HashSet [java.lang:type=MemoryPool,name=CMS Old Gen, java.lang:type=Memory, ...]
What attributes does a bean have?
(jmx/attribute-names "java.lang:type=Memory") -> (:Verbose :ObjectPendingFinalizationCount :HeapMemoryUsage :NonHeapMemoryUsage)
What is the value of an attribute?
(jmx/read "java.lang:type=Memory" :ObjectPendingFinalizationCount) -> 0 (jmx/read "java.lang:type=Memory" [:HeapMemoryUsage :NonHeapMemoryUsage]) -> {:NonHeapMemoryUsage {:used 16674024, :max 138412032, :init 24317952, :committed 24317952}, :HeapMemoryUsage {:used 18619064, :max 85393408, :init 0, :committed 83230720}}
Can't I just have all the attributes in a Clojure map?
(jmx/mbean "java.lang:type=Memory") -> {:NonHeapMemoryUsage {:used 16674024, :max 138412032, :init 24317952, :committed 24317952}, :HeapMemoryUsage {:used 18619064, :max 85393408, :init 0, :committed 83230720}, :ObjectPendingFinalizationCount 0, :Verbose false}
Can I find and invoke an operation?
(jmx/operation-names "java.lang:type=Memory") -> (:gc) (jmx/invoke "java.lang:type=Memory" :gc) -> nil
What about some other process? Just run any of the above code inside a with-connection:
(jmx/with-connection {:host "localhost", :port 3000} (jmx/mbean "java.lang:type=Memory")) -> {:ObjectPendingFinalizationCount 0, :HeapMemoryUsage ... etc.}
Can I serve my own beans? Sure, just drop a Clojure ref into an instance of clojure.java.jmx.Bean, and the bean will expose read-only attributes for every key/value pair in the ref:
(jmx/register-mbean (create-bean (ref {:string-attribute "a-string"})) "my.namespace:name=Value")
JMX support for Clojure Usage (require '[clojure.java.jmx :as jmx]) What beans do I have? (jmx/mbean-names "*:*") -> #<HashSet [java.lang:type=MemoryPool,name=CMS Old Gen, java.lang:type=Memory, ...] What attributes does a bean have? (jmx/attribute-names "java.lang:type=Memory") -> (:Verbose :ObjectPendingFinalizationCount :HeapMemoryUsage :NonHeapMemoryUsage) What is the value of an attribute? (jmx/read "java.lang:type=Memory" :ObjectPendingFinalizationCount) -> 0 (jmx/read "java.lang:type=Memory" [:HeapMemoryUsage :NonHeapMemoryUsage]) -> {:NonHeapMemoryUsage {:used 16674024, :max 138412032, :init 24317952, :committed 24317952}, :HeapMemoryUsage {:used 18619064, :max 85393408, :init 0, :committed 83230720}} Can't I just have *all* the attributes in a Clojure map? (jmx/mbean "java.lang:type=Memory") -> {:NonHeapMemoryUsage {:used 16674024, :max 138412032, :init 24317952, :committed 24317952}, :HeapMemoryUsage {:used 18619064, :max 85393408, :init 0, :committed 83230720}, :ObjectPendingFinalizationCount 0, :Verbose false} Can I find and invoke an operation? (jmx/operation-names "java.lang:type=Memory") -> (:gc) (jmx/invoke "java.lang:type=Memory" :gc) -> nil What about some other process? Just run *any* of the above code inside a with-connection: (jmx/with-connection {:host "localhost", :port 3000} (jmx/mbean "java.lang:type=Memory")) -> {:ObjectPendingFinalizationCount 0, :HeapMemoryUsage ... etc.} Can I serve my own beans? Sure, just drop a Clojure ref into an instance of clojure.java.jmx.Bean, and the bean will expose read-only attributes for every key/value pair in the ref: (jmx/register-mbean (create-bean (ref {:string-attribute "a-string"})) "my.namespace:name=Value")
(attribute-names n)
All attribute names available on an MBean.
All attribute names available on an MBean.
(create-bean state-ref)
Expose a reference as a JMX bean. state-ref should be a Clojure reference (ref, atom, agent) containing a map.
Using an agent for the state-ref is not recommended when the bean may be modified with the setAttribute(s) methods. The setAttribute(s) methods will block on the agent to complete all submitted actions (via await).
Expose a reference as a JMX bean. state-ref should be a Clojure reference (ref, atom, agent) containing a map. Using an agent for the state-ref is not recommended when the bean may be modified with the setAttribute(s) methods. The setAttribute(s) methods will block on the agent to complete all submitted actions (via await).
(invoke n op & args)
Invoke an operation an an MBean. See also: invoke-signature
Invoke an operation an an MBean. See also: invoke-signature
(invoke-signature n op signature & args)
Invoke an operation an an MBean. You must also supply the signature of the operation. This is useful in cases where the operation is overloaded. Otherwise you should use the 'invoke' operation which will determine the signature for you.
The signature parameter is a sequence of strings that describes the method parameter types in order.
Invoke an operation an an MBean. You must also supply the signature of the operation. This is useful in cases where the operation is overloaded. Otherwise you should use the 'invoke' operation which will determine the signature for you. The signature parameter is a sequence of strings that describes the method parameter types in order.
(mbean n)
Like clojure.core/bean, but for JMX beans. Returns a read-only map of a JMX bean's attributes. If an attribute it not supported, value is set to the exception thrown.
Like clojure.core/bean, but for JMX beans. Returns a read-only map of a JMX bean's attributes. If an attribute it not supported, value is set to the exception thrown.
(mbean-names n)
Finds all MBeans matching a name on the current connection.
Finds all MBeans matching a name on the current *connection*.
(operation-names n)
All operation names available on an MBean.
All operation names available on an MBean.
(register-mbean mbean mbean-name)
Register an mbean with the current connection.
Register an mbean with the current *connection*.
(unregister-mbean mbean-name)
Unregister mbean named mbean-name with the current connection.
Unregister mbean named mbean-name with the current *connection*.
(with-connection opts & body)
Execute body with a JMX connection created based on opts. opts can include [default]:
:protocol The protocol to use [rmi:///jndi/rmi] :host The host to connect to [localhost] :port The port to connect to [3000] :jndi-path The jndi-path to use [jmxuri] :url The full url (as a String) to use instead of generating a rmi url from the above options [nil] :environment A map representing the environment used for the connection. See JMXConnectorFactory/connect for details [{}]
Execute body with a JMX connection created based on opts. opts can include [default]: :protocol The protocol to use [rmi:///jndi/rmi] :host The host to connect to [localhost] :port The port to connect to [3000] :jndi-path The jndi-path to use [jmxuri] :url The full url (as a String) to use instead of generating a rmi url from the above options [nil] :environment A map representing the environment used for the connection. See JMXConnectorFactory/connect for details [{}]
(write! n attr value)
Write an attribute value.
Write an attribute value.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close