API for jmx
- ()
by Stuart Halloway
Usage:
(ns your-namespace
(:require clojure.contrib.jmx))
Overview
JMX support for Clojure
Requires post-Clojure 1.0 git edge for clojure.test, clojure.backtrace.
This is prerelease.
This API will change.
Send reports to stu@thinkrelevance.com.
Usage
(require '[clojure.contrib.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
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.contrib.jmx.Bean, and the bean
will expose read-only attributes for every key/value pair
in the ref:
(jmx/register-mbean
(Bean.
(ref {:string-attribute "a-string"}))
"my.namespace:name=Value")
Public Variables and Functions
*connection*
var
The connection to be used for JMX ops. Defaults to the local process.
Source
as-object-name
multimethod
Usage: (as-object-name string-or-name)
Interpret an object as a JMX ObjectName.
Source
attribute-info
function
Usage: (attribute-info object-name attr-name)
Get the MBeanAttributeInfo for an attribute.
Source
attribute-names
function
Usage: (attribute-names n)
All attribute names available on an MBean.
Source
build-attribute-info
function
Usage: (build-attribute-info attr-name attr-value)
(build-attribute-info name type desc readable? writable? is?)
Construct an MBeanAttributeInfo. Normally called with a key/value pair from a Clojure map.
Source
guess-attribute-typename
function
Usage: (guess-attribute-typename value)
Guess the attribute typename for MBeanAttributeInfo based on the attribute value.
Source
jmx->clj
multimethod
No usage documentation available
Coerce JMX data structures into Clojure data.
Handles CompositeData, TabularData, maps, and atoms.
Source
jmx-url
function
Usage: (jmx-url)
(jmx-url overrides)
Build a JMX URL from options.
Source
map->attribute-infos
function
Usage: (map->attribute-infos attr-map)
Construct an MBeanAttributeInfo[] from a Clojure associative.
Source
maybe-atomize
function
Usage: (maybe-atomize k)
Convert a list of length 1 into its contents, leaving other things alone.
Used to simplify keys in the tabular data API.
Source
maybe-keywordize
function
Usage: (maybe-keywordize s)
Convert a string key to a keyword, leaving other types alone. Used to
simplify keys in the tabular data API.
Source
mbean
function
Usage: (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.
Source
mbean-names
function
Usage: (mbean-names n)
Finds all MBeans matching a name on the current *connection*.
Source
op-param-types
function
Usage: (op-param-types n op)
The parameter types (as class name strings) for operation op on n.
Used for invoke.
Source
operation
function
Usage: (operation n op)
The MBeanOperationInfo for operation op on mbean n. Used by invoke.
Source
operation-names
function
Usage: (operation-names n)
All operation names available on an MBean.
Source
operations
function
Usage: (operations n)
All oeprations available on an MBean.
Source
raw-read
function
Usage: (raw-read n attr)
Read an mbean property. Returns low-level Java object model for
composites, tabulars, etc. Most callers should use read.
Source
read
var
Read an mbean property.
Source
read-supported
function
Usage: (read-supported n attr)
Calls read to read an mbean property, *returning* unsupported
operation exceptions instead of throwing them. Used to keep mbean
from blowing up. Note: There is no good exception that aggregates
unsupported operations, hence the overly-general catch block.
Source
readable?
function
Usage: (readable? n attr)
Is attribute readable?
Source
with-connection
macro
Usage: (with-connection opts & body)
Execute body with JMX connection specified by opts. opts can also
include an optional :environment key which is passed as the
environment arg to JMXConnectorFactory/connect.
Source