NAME

check_jmx4perl - Nagios check using jmx4perl for accessing JMX information

SYNOPSIS

# Check used heap memory for absolute values
check_jmx4perl --url http://localhost:8888/j4p \
               --name memory_used \
               --mbean java.lang:type=Memory \
               --attribute HeapMemoryUsage \ 
               --path used \
               --critical 10000000 \
               --warning   5000000 


# Check for string values by comparing them literally
check_jmx4perl --url http://localhost::8888/j4p \
               --mbean myDomain:name=myMBean \
               --attribute stringAttribute \
               --string \
               --critical 'Stopped' \
               --warning '!Started'

# Check used heap memory for absolute values by using an alias
check_jmx4perl --url http://localhost:8888/j4p \
               --alias MEMORY_HEAP_USED \
               --critical 10000000 \
               --warning   5000000 

# Check that the used heap memory is below 80% of the available memory
check_jmx4perl --url http://localhost:8888/j4p \
               --alias MEMORY_HEAP_USED \
               --base MEMORY_HEAP_MAX \ 
               --critical :80

# Check that no more than 5 threads are started in a minute
check_jmx4perl --url http://localhost:8888/j4p \
               --alias THREAD_COUNT_STARTED \
               --delta 60 \
               --critical 5

# Execute a JMX operation on an MBean and use the return value for threshold
check_jmx4perl --url http://localhost:8888/j4p \
               --mbean jmx4perl:type=Runtime \
               --operation getNrQueriesFor \
               --critical 10 \
               "operation" \
               "java.lang:type=Memory" \
               "gc" 

# Use check_jmx4perl in proxy mode
check_jmx4perl --url http://localhost:8888/j4p \
               --alias MEMORY_HEAP_USED \
               --critical 10000000 \
               --target service:jmx:rmi:///jndi/rmi://bhut:9999/jmxrmi
 
# Use predefined checks in a configuration file with a server alias
# Server alias is 'webshop', check is about requests per minute for the 
# servlet 'socks_shop'
check_jmx4perl --config /etc/nagios/check_jmx4perl/tomcat.cfg
               --server webshop \
               --check tc_servlet_requests \
               --critical 1000 \
               socks_shop

DESCRIPTION

Nagios plugin for monitoring Java applications which expose JMX data via a jmx4perl agent.

This plugin can be used in two ways: First, all required parameters for identifying the JMX information can be given via the command line. Second, a configuration file can be used to define one or more nagios checks. This is the recommend mode, since it allows for more advanced features not available when using the command line alone. Each command line argument has an equivalent configuration option.

Before we describe the w

BASICS

MBeans

JMX's central entity is an E<MBean>. An MBean exposes management information in a well defined way. Each MBean has a unique name with the following structure:

domain:attribute1=value1,attribute2=value2, .....

E.g.

java.lang:type=Memory

Before you start monitoring, you need to know the MBean name. There are various ways to identify the MBean:

  • Use jmx4perl --list to list all registered MBeans. In addition jmx4perl --attributes dumps out all known MBean attributes along with their values. (Be careful, the output can be quite large)

  • Use j4psh for interactively exploring the JMX namespace.

  • Use an alias. An alias is a shortcut for an MBean name, predefined by JMX::Jmx4Perl. All known aliases can be shown with jmx4perl. Since each platform can have slightly different MBean names for the same information, this is extra level of indirection might help in identifying MBeans. See below for more about aliases.

  • Use a predefined check. check_jmx4perl comes with quite some checks predefined in various configuration files. These are ready for use out of the box.

  • As your Java application development team for application specific MBean names.

    =back.

Operational Modes

check_jmx4perl can obtain the information to monitor from two sources: Either as MBean attributes or as return value from JMX operations. Since JMX values can be any Java Object, it is important to understand, how check_jmx4perl (or JMX::Jmx4Perl in general) handles this situation.

Simple data types can be used directly in threshhold checking. I.e. the following data types can be used directly

Integer
Long
Float
Double
Boolean
String

String and Boolean can be used in string checks only, whereas the others can be used in both, numeric and string checks.

Pathes

For more complex types, check_jmx4perl provides the concept of so called pathes for specifying an inner attribute of a more complex attribute or operation return value. A path is build of parts, separated by slashes (/). It's simplified variant of an XPath expression for accessing parts of an XML document. Each part points to an level of the JSON serialized object.

For example, the MBean java.lang:type=Memory exposes an attribute called HeapMemoryUsage. This attribute is a combound data type, which contains multiple entries. Looking with jmx4perl at this attribute

$ jmx4perl http://localhost:8080/j4p read java.lang:type=Memory HeapMemoryUsage
$VAR1 = {
          'committed' => '85000192',
          'used' => '8135440',
          'max' => '129957888',
          'init' => '0'
        };

one sees, that there are 4 values coming with the reponse. With a path used one can directly pick the used heap memory usage (8135440 bytes in this case) which can be used in a threshold check. This path can be used with check_jmx4perl like

$ check_jmx4perl --url http://localhost:8080/j4p \ 
                 --mbean java.lang:type=Memory \ 
                 --attribute HeapMemoryUsage \
                 --path used \
                 --critical 100000000
OK - [java.lang:type=Memory,HeapMemoryUsage,used] : Value 10136056 in range | ...
1
=head3 Attributes

Attribute are values which can be obtained from MBeans. They can be of a simple data type like a string or an integer, but they can be arbitrarly complex (e.g an arbitrary Java type). Simple data types can be used directly for threshold checking where the value is compared against a critical or warning threshold directly.

-- Values --

Operations

Aliases

Relative Checks

Incremental Checks

Output Tuning

Proxy mode

COMMAND LINE

The pure command line interface (without a configuration file) is mostly suited for simple checks where the predefined defaults are suitable. For all other use case, a configuration file fits better.

Command Line Options

Command for providing Nagios conmpliant output for JMX response fetched via JMX::Jmx4Perl. It knows about critical (via --critical) and warning (via --warning) thresholds.

You can also use direct string comparison. In this case --critical and --warning are not treated as numerical values but as string types. They are compared literally against the value retrieved and yield the corresponding Nagios status if matched. If the threshold is given with a leading !, the condition is negated. E.g. a --critical '!Running' given returns a CRITICAL if the value is not equals to Running. As a final option you can also use a regular expression by using qr/.../ as threshold value (substitute ... with the pattern to used for comparison). Boolean values are returned as true or false strings from the agent, so you can check for them as well with this kind of string comparison.

Whether string comparison or a numerical check is used is determined automatically based on the value returned. You can enforce a particular mode by providing the option --numeric or --string respectively.

Values obtained from the server can be interpreteted as relative values when --base is given. The argument provided here is first tried as an alias name or checked as an absolute, numeric value. Alternatively, you can use a full MBean/Attribute/Path specification by using a / as separator, e.g.

... --base java.lang:type=Memory/HeapMemoryUsage/max ...

If one of these parts (the path is optional) contains a slash within its name, the part must be URI encoded. I.e. all parts are URI decoded before usages as naming pattern. In any case, using an alias or direct MBean names, the base value is fetched first for calculating the relative value. For a numeric value given here this is of course not necessary.

--delta switches on incremental mode in which the difference between two following values is used. The optional argument are interpreted as seconds which are used for calculating the speed of growth. If not given, only the difference between the current and the latest value is taken. --delta doesn't work with --base.

With the option --operation a JMX operation is triggered and the return value used for threshold calculations. Additionally, if use an operation alias with --alias, you can ommit --operation and --mbean. Any arguments required for the operation need to be provided as additional arguments.

The output of check_jmx4perl can be highly customized. First of all, you can provide a unit-of-measurement with the option --unit. This specifies how the the attribute or an operation's return value should be interpreted. The units available are

B  - Byte
KB - Kilo Byte
MB - Mega Byte
GM - Giga Byte
TM - Terra Byte

us - Microseconds
ms - Milliseconds
s  - Seconds
m  - Minutes
h  - Hours
d  - Days

The unit will be used for performance data as well as for the plugin's output. Large numbers are converted to larger units (and reverse for small number that are smaller than 1). E.g. 2048 KB is converted to 2 MB. However, beautifying by conversion is only performed for the plugin output, not for the performance data for which no conversions happens at all.

Beside unit handling, you can provide your own label for the Nagios output via --label. The provided option is interpreted as a pattern with the following placeholders:

%v   the absolute value 
%f   the absolute value as floating point number
%r   the relative value for relative calculations (--base)
%u   the value's unit for the output when --unit is used
%w   the the base value's for the output unit when --unit is used
%b   the absolut base value as it is used with --base 
%c   the Nagios exit code in the Form "OK", "WARNING", "CRITICAL" 
     or "UNKNOWN"
%t   Threshold value which fails ("" when the check doesn't fail)
%n   name, either calulated automatically or given with --name
%d   the delta value used for normalization when using incremental mode

Note that %u and %w are typically not the same as the --unit option. They specify the unit after the conversion for the plugin output as described above. You can use the same modifiers as for sprintf to fine tune the output.

Example:

check_jmx4perl --url http://localhost:8888/j4p \
               --alias MEMORY_HEAP_USED \
               --base MEMORY_HEAP_MAX \ 
               --critical :80 \
               --label "Heap-Memory: %.2r% used (%.2v %u / %.2b %u)" \
               --unit B

will result in an output like

OK - Heap-Memory: 3.48% used (17.68 MB / 508.06 MB) | '[MEMORY_HEAP_USED]'=3.48%;;:80

check_jmx4perl can be used in a proxy mode as well. When the option --target is given, the agent servlet use this url as a JMX Service URL and tries to connect via a JSR-160 to specified target to obtain the JMX information from there. Additionally --target-user and --target-password can be used to provide credentials if the target server is secure with user- and password name. Please see the manual for more information about the proxy mode and its limitations.

CONFIGURATION

Multichecks

Parent checks

Parameterized checks

Predefined checks

LICENSE

This file is part of jmx4perl.

Jmx4perl is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

jmx4perl is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with jmx4perl. If not, see <http://www.gnu.org/licenses/>.

AUTHOR

roland@cpan.org

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 88:

Unknown E content in E<MBean>

Around line 133:

You forgot a '=back' before '=head2'