|
NAMEcheck_jmx4perl - Nagios plugin using jmx4perl for accessing JMX data remotelySYNOPSIS# Check for used heap memory (absolute values) check_jmx4perl --url http://localhost:8888/jolokia \ --name memory_used \ --mbean java.lang:type=Memory \ --attribute HeapMemoryUsage \ --path used \ --critical 10000000 \ --warning 5000000 # Check that used heap memory is less than 80% of the available memory check_jmx4perl --url http://localhost:8888/jolokia \ --alias MEMORY_HEAP_USED \ --base MEMORY_HEAP_MAX \ --critical :80 # 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 # Check for string values by comparing them literally check_jmx4perl --url http://localhost::8888/jolokia \ --mbean myDomain:name=myMBean \ --attribute stringAttribute \ --string \ --critical 'Stopped' \ --warning '!Started' # Check that no more than 5 threads are started in a minute check_jmx4perl --url http://localhost:8888/jolokia \ --alias THREAD_COUNT_STARTED \ --delta 60 \ --critical 5 # Execute a JMX operation on an MBean and use the return value for threshold # Here a thread-deadlock is detected. check_jmx4perl --url http://localhost:8888/jolokia \ --mbean java.lang:type=Threading \ --operation findDeadlockedThreads \ --null no-deadlock \ --string \ --critical '!no-deadlock' \ --critical 10 # Use check_jmx4perl in proxy mode check_jmx4perl --url http://localhost:8888/jolokia \ --alias MEMORY_HEAP_USED \ --critical 10000000 \ --target service:jmx:rmi:///jndi/rmi://bhut:9999/jmxrmi DESCRIPTION"check_jmx4perl" is a Nagios plugin for monitoring Java applications. It uses an agent based approach for accessing JMX exposed information remotely.Before start using "check_jmx4perl" an agent must be installed on the target platform. For JEE application server this is a simple webapplication packaged as a "war" archive. For other platforms, other agents are available, too. Please refer to the "README" for installation instructions and the supported platforms. "check_jmx4perl"s can also be used in an agentless mode (i.e. no agent needs to be installed on the target platform). See "Proxy mode" for details. This plugin can be configured in two ways: Either, all required parameters for identifying the JMX information can be given via the command line. Or, a configuration file can be used to define one or more Nagios checks. This is the recommended way, since it allows for more advanced features not available when using the command line alone. Each command line argument has an equivalent option in the configuration files, though. This documentation contains four parts. First, a tutorial gives a 5 minute quickstart for installing and using "check_jmx4perl". The middle part offers some technical background information on JMX itself, the features provided by this plugin and finally the command line arguments and the configuration file directives are described. TUTORIALBefore we dive into the more nifty details, this 5 minutes quickstart gives a simple cooking recipe for configuration and setup of "check_jmx4perl".
All available command line options are described in "COMMAND LINE".
Configuration files are very powerful and are the recommended way for configuring "check_jmx4perl" for any larger installation. Features like multi checks are even only available when using a configuration file. The syntax for configuration files are explained in depth in "CONFIGURATION".
Installing and using jmx4perl is really that easy. The Nagios configuration in this example is rather simplistic, of course a more flexible Nagios setup is possible. The blog post <http://labs.consol.de//blog/jmx4perl/check_jmx4perl-einfache-servicedefinitionen/> (written by Gerhard Lausser) shows some advanced configuration setup. (It is in german, but the automatic translation from <http://bit.ly/bgReAs> seems to be quite usable). REFERENCEThis section explains the JMX basics necessary to better understand the usage of "check_jmx4perl". It tries to be as brief as possible, but some theory is required to get the link to the Java world.MBeansJMX's central entity is an "MBean". An MBean exposes management information in a well defined way. Each MBean has a unique name called Object Name with the following structure:domain:attribute1=value1,attribute2=value2, ..... E.g. java.lang:type=Memory points to the MBean which lets you access the memory information of the target server. Unfortunately, except for so called MXBeans (<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/package-summary.html>) there is no standard naming for MBeans. Each platform uses its own. There used to be a naming standard defined in JSR77 (<http://jcp.org/en/jsr/detail?id=77>), unfortunately it was never widely adopted. There are various ways for identifying MBeans on a server:
Attributes and Operations"check_jmx4perl" can obtain the information to monitor from two sources: Either as MBean attributes or as a return value from JMX operations. Since JMX values can be any Java object, it is important to understand, how "check_jmx4perl" (or jmx4perl in general) handles this situation.Simple data types can be used directly in threshold checking. I.e. the following data types can be used directly
"String" and "Boolean" can be used in string checks only, whereas the others can be used in both, numeric and string checks (see "String checks"). For numeric checks, the threhsholds has to be specified according to the format defined in <http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT> Paths For more complex types, "check_jmx4perl" provides the concept of so called paths for specifying an inner attribute of a more complex value. A path contains parts separated by slashes (/). It is similar to an XPath expression for accessing parts of an XML document. Each part points to an inner level of a complex object. For example, the MBean "java.lang:type=Memory" exposes an attribute called "HeapMemoryUsage". This attribute is a compound data type which contains multiple entries. Looking with "jmx4perl" at this attribute $ jmx4perl http://localhost:8080/jolokia read java.lang:type=Memory HeapMemoryUsage { committed => 85000192, init => 0 max => 129957888, used => 15106608, } it can be seen, 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 then can be used for a threshold check. $ check_jmx4perl --url http://localhost:8080/jolokia \ --mbean java.lang:type=Memory \ --attribute HeapMemoryUsage \ --path used \ --critical 100000000 OK - [java.lang:type=Memory,HeapMemoryUsage,used] : Value 10136056 in range | ... Attributes Attributes are values obtained from MBean properties. Complex values are translated into a JSON structure on the agent side, which works for most types. To access a single value from a complex value, the path mechanism described above can be used. Thresholds can be applied to simple data types only, so for complex attributes a path is required. Operations The return values of operations can be used for threshold checking, too. Since a JMX exposed operation can take arguments, these has to be provided as extra arguments on the command line or in the configuration via the "Args" configuration directive. Due to the agent's nature and the protocol used (JSON), only simple typed arguments like strings, numbers or booleans ("true"/"false") can be used. Example: $ check_jmx4perl --url http://localhost:8888/jolokia \ --mbean jolokia:type=Runtime \ --operation getNrQueriesFor \ --critical 10 \ "operation" \ "java.lang:type=Memory" \ "gc" This example contacts a MBean "jolokia:type=Runtime" registered by the jolokia agent in order to check for the number of queries for a certain MBean via this agent. For this purpose an JMX operation "getNrQueriesFor" is exposed which takes three arguments: The type ("operation"/"attribute"), the MBean's ObjectName and the operation/attribute name which was called. If the operation to be called is an overloaded operation (i.e. an operation whose name exists multiple times on the same MBean but with different parameter types), the argument types must be given within parentheses: --operation checkUserCount(java.lang.String,java.lang.String) AliasesAliases are shortcut for common MBean names and attributes. E.g. the alias "MEMORY_HEAP_MAX" specifies the MBean "java.lang:type=Memory", the attribute "HeapMemoryUsage" and the path "max". Aliases can be specified with the "--alias" option or with the configuration directive "Alias". Aliases can be translated to different MBean names on different application server. For this "check_jmx4perl" uses an autodetection mechanism to determine the target platform. Currently this mechanism uses one or more extra server round-trips. To avoid this overhead, the "--product" option (configuration: "Product") can be used to specify the target platform explicitely. This is highly recommended in case you are using the aliasing feature.Aliases are not extensible and can not take any parameters. All availables aliases can be viewed with jmx4perl aliases A much more flexible alternative to aliases are parameterized checks, which are defined in a configuration file. See "CONFIGURATION" for more details about parameterized checks. Relative ChecksRelative values are often more interesting than absolute numbers. E.g. the knowledge that 140 MBytes heap memory is used is not as important as the knowledge, that 56% of the available memory is used. Relative checks calculate the ratio of a value to a base value. (Another advantage is that Nagios service definitions for relative checks are generic as they can be applied for target servers with different memory footprints).The base value has to be given with "--base" (configuration: "Base"). 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 slash must be escaped with a backslash (\/). Backslashes in MBean names are escaped with a double backslash (\\). Alternatively "--base-mbean", "--base-attribute" and "--base-path" can be used to specify the parts of the base value separately. Example: check_jmx4perl --url http://localhost:8080/jolokia \ --value java.lang:type=Memory/HeapMemoryUsage/used \ --base java.lang:type=Memory/HeapMemoryUsage/max \ --critical 90 check_jmx4perl --url http://localhost:8080/jolokia \ --value java.lang:type=Memory/HeapMemoryUsage/used \ --base-mbean java.lang:type=Memory \ --base-attribute HeapMemoryUsage \ --base-path max \ --critical 90 This check will trigger a state change to CRITICAL if the used heap memory will exceed 90% of the available heap memory. Incremental ChecksFor some values it is worth monitoring the increase rate (velocity). E.g. for threads it can be important to know how fast threads are created.Incremental checks are switched on with the "--delta" option (configuration: "Delta"). This option takes an optional argument which is interpreted as seconds for normalization. Example: check_jmx4perl --url http://localhost:8080/jolokia \ --mbean java.lang:type=Threading \ --attribute TotalStartedThreadCount \ --delta 60 \ --critical 5 This will fail as CRITICAL if more than 5 threads are created per minute (60 seconds). Technically "check_jmx4perl" uses the history feature of the jolokia agent deployed on the target server. This will always store the result and the timestamp of the last check on the server side and returns these historical values on the next check so that the velocity can be calculated. If no value is given for "--delta", no normalization is used. In the example above, without a normalization value of 60, a CRITICAL is returned if the number of threads created increased more than 5 between two checks. "--delta" doesn't work yet with "--base" (e.g. incremental mode for relative checks is not available). String checksIn addition to standard numerical checks, direct string comparison can be used. This mode is switched on either explicitely via "--string" (configuration: "String") or by default implicitely if a heuristics determines that a value is non-numeric. Numeric checking can be enforced with the option "--numeric" (configuration: Numeric).For string checks, "--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'" returns "CRITICAL" if the value not equals to "Running". Alternatively 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. No performance data will be generated for string checks by default. This can be switched on by providing "--perfdata on" (or ""PerfData on"" in the configuration). However, this probably doesn't make much sense, though. Output TuningThe output of "check_jmx4perl" can be highly customized. A unit-of-measurement can be provided with the option "--unit" (configuration: "Unit") which specifies how the the attribute or an operation's return value should be interpreted. The units available areB - Byte KB - Kilo Byte MB - Mega Byte GB - Giga Byte TB - 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 automatically (and reverse for small number that are smaller than 1). E.g. "2048 KB" is converted to "2 MB". 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 as percentage (--base) %q the relative value as ratio of value to base (--base) %u the value's unit for the output when --unit is used (after shortening) %w the base value's unit for the output when --unit is used (after shortening) %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 failed ("" 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 %y WARNING threshold as configured %z CRITICAL threshold as configured 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 length modifiers as for "sprintf" to fine tune the output. Example: check_jmx4perl --url http://localhost:8888/jolokia \ --alias MEMORY_HEAP_USED \ --base MEMORY_HEAP_MAX \ --critical :80 \ --label "Heap-Memory: %.2r% used (%.2v %u / %.2b %w)" \ --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 SecuritySince the jolokia-agent is usually a simple war-file, it can be secured as any other Java Webapplication. Since setting up authentication is JEE Server specific, a detailed instruction is beyond the scope of this document. Please refer to your appserver documentation, how to do this. At the moment, "check_jmx4perl" can use Basic-Authentication for authentication purposes only.In addition to this user/password authentication, the jolokia-agent uses a policy file for fine granular access control. The policy is defined with an XML file packaged within the agent. In order to adapt this to your needs, you need to extract the war file, edit it, and repackage the agent with a policy file. A future version of jmx4perl might provide a more flexible way for changing the policy. In detail, the following steps are required:
The downloaded sample policy file jolokia-access.xml contains inline documentation and examples, so you can easily adapt it to your environment. Restrictions can be set to on various parameters : Client IP address Access to the jolokia-agent can be restricted based on the client IP accessing the agent. A single host, either with hostname or IP address can be set or even a complete subnet. Example: <remote> <host>127.0.0.1</host> <host>10.0.0.0/16</host> </remote> Only the localhost or any host in the subnet 10.0 is allowed to access the agent. If the "<remote>" section is missing, access from all hosts is allowed. Commands The access can be restricted to certain commands. Example: <commands> <command>read</command> </commands> This will only allow reading of attributes, but no other operation like execution of operations. If the "<commands>" section is missing, any command is allowed. The commands known are
Specific MBeans The most specific policy can be put on the MBeans themselves. For this, two sections can be defined, depending on whether a command is globaly enabled or denied.
Proxy mode"check_jmx4perl" can be used in an agentless mode as well, i.e. no jolokia-agent needs to deployed on the target server. The setup for the agentless mode is a bit more complicated, though:
Advantages
Disadvantages
To summarize, I would always recommend the agent mode over the proxy mode except when an agentless operation is required (e.g. for policy reasons). COMMAND LINEThe pure command line interface (without a configuration file) is mostly suited for simple checks where the predefined defaults are suitable. For all other use cases, a configuration file fits better."check_jmx4perl" knows about the following command line options:
CONFIGURATIONUsing "check_jmx4perl" with a configuration file is the most powerful way for defining Nagios checks. A simple configuration file looks like# Define server connection parameters <Server tomcat> Url = http://localhost:8080/jolokia </Server> # A simple heap memory check with a critical threshold of # 90% of the maximal heap memory. <Check memory_heap> Value = java.lang:type=Memory/HeapMemoryUsage/used Base = java.lang:type=Memory/HeapMemoryUsage/max Unit = B Label = Heap-Memory: %.2r% used (%.2v %u / %.2b %u) Name = Heap Critical = 90 </Check> A configuration file is provided on the command line with the option "--config". It can be divided into two parts: A section defining server connection parameters and a section defining the checks themselves. <Server>With "<Server name>" the connection parameters for a specific server is defined. In order to select a server the "--server name" command line option has to be used. Within a "<Server>" configuration element, the following keys can be used:
Single CheckWith "<Check>" a single check can be defined. It takes any option available also available via the command line. Each check has a name, which can be referenced from the commandline with the option "--check name".Example: <Check memory_heap> Value = java.lang:type=Memory/HeapMemoryUsage/used Base = java.lang:type=Memory/HeapMemoryUsage/max Label = Heap-Memory: Name = Heap Critical = 90 </Check> The "<Check>" section knows about the following directives:
IncludesChecks can be organized in multiple configuration files. To include another configuration file, the "include" directive can be used:include tomcat.cfg include threads.cfg include memory.cfg If given as relative path, the configuration files are looked up in the same directory as the current configuration file. Absolute paths can be given, too. Parent checksWith "check_jmx4perl" parent checks it is possible to define common base checks, which are usable in various sub-checks. Any "<Check>" can be a parent check as soon as it is referenced via a "Use" directive from within another check's definition. When a check with a parent check is used, its configuration is merged with this from the parent check with own directives having a higher priority. Parent checks can have parent checks as well (and so on).For example, consider the following configuration: <Check grand_parent> Name grand_parent Label GrandPa Critical 10 </Check> <Check parent_1> Use grand_parent Name parent_1 Critical 20 </Check> <Check parent_2> Name parent_2 Warning 20 </Check> <Check check> Use parent_1,parent_2 Warning 40 </Check> In this scenario, when check "check" is used, it has a "Name" ""parent_2"" (last parent check in "Use"), a "Label" "GrandPa" (inherited from "grand_parent" via "parent_1"), a "Critical" 20 (inherited from "parent_1") and a "Warning" 40 (directly give in the check definition). A parent value of a configuration directive can be refered to with the placeholder $BASE. For example: <Check parent> Name Parent </Check> <Check check> Use parent Name Child: $BASE </Check> This will lead to a "Name" ""Child: Parent"" since $BASE is resolved to the parent checks valus of "Name", "Parent" in this case. The base value is searched upwards in the inheritance hierarchy (parent, grand parent, ...) until a value is found. If nonen is found, an empty string is used for $BASE. Parameterized checksChecks can be parameterized, i.e. they can take arguments which are replaced in the configuration during runtime. Arguments are used in check definition via the positional format $0, $1, .... (e.g. $0 is the first argument given). Arguments can either be given on the command line as extra arguments to "check_jmx4perl" or within the "Use" directive to provide arguments to parent checks.Example: <Check parent> Name $0 Label $1 </Check> <Check child_check> Use parent($0,"Check-Label") .... </Check> $ check_jmx4perl --check child_check .... "Argument-Name" OK - Check-Label | 'Argument-Name'= .... As it can be seen in this example, arguments can be propagated to a parent check. In this case, $0 from the command line ("Argument-Name") is passed through to the parent check which uses it in the "Name" directive. $1 from the parent check is replaced with the value ""Check-Label"" given in the "Use" directive of the child check. Parameters can have default values. These default values are taken in case an argument is missing (either when declaring the parent check or missing from the command line). Default values are specified with ${arg-nr":"default"}". For example, <Check relative_base> Label = %.2r% used (%.2v %u / %.2b %w) Critical = ${0:90} Warning = ${1:80} </Check> defines a default value of 90% for the critical threshold and 80% for the warning threshold. If a child check uses this parent definition and only wants to ommit the first parameter (but explicitely specifying the second parameter) it can do so by leaving the first parameter empty: <Check child> Use relative_base(,70) </Check> MultichecksMultiple checks can be combined to a single MultiCheck. The advantage of a multi check is, that multiple values can be retrieved from the server side with a single HTTP request. The output is conformant to Nagios 3 multiline format. It will lead to a "CRITICAL" value as soon as one check is critical, same for "WARNING". If both, "CRITICAL" and "WARNING" is triggered by two or more checks, then "CRITICAL" take precedence.If a single check within a multi check fails with an exception (e.g. because an MBean is missing), its state becomes "UNKNOWN". "UNKNOWN" is the highest state in so far that it shadows even "CRITICAL" (i.e. if a single check is "UNKNOWN" the whole multi check is "UNKNOWN", too). This can be changed by providing the command line option "--unknown-is-critical" in which case all "UNKNOWN" errors are mapped to "CRITICAL". A multi-check can be defined with the directive "<MultiCheck>", which contain various references to other "<Check>" definitions or other multi check definitions. Example: <MultiCheck all> MultiCheck memory MultiCheck threads </MultiCheck> <MultiCheck memory> Check memory_heap($0,80) Check memory_pool_base("CMS Perm Gen",90,80) </MultiCheck> <MultiCheck threads> Check thread_inc Check thread_deadlock </MultiCheck> Here a multi check group memory has been defined with reference to two checks, which must exist somewhere else in the configuration file. As it can be seen, parameters can be given through to the check in the usual way (literally or with references to command line arguments). The group all combines the two groups memory and thread, containing effectively four checks. A multi-check is referenced from the command line like any other check: $ check_jmx4perl .... --check all 90 (90 is the argument which replaces $0 in the definition above). The summary label in a multi check can be configured, too. Example: <MultiCheck memory> SummaryOk All %n checks are OK SummaryFailure %e of %n checks failed [%d] ... </MultiCheck> These format specifiers can be used: %n Number of all checks executed %e Number of failed checks %d Details which checks failed Predefined checks"check_jmx4perl" comes with a collection of predefined configuration for various application servers. The configurations can be found in the directory config within the toplevel distribution directory. The configurations are fairly well documented inline.common.cfg Common check definitions, which can be used as parents for own checks. E.g. a check "relative_base" can be used as parent for getting a nicely formatted output message. memory.cfg Memory checks for heap and non-heap memoy as well as for various memory pools. Particularly interesting here is the so called Perm Gen pool as it holds the java type information which can overflow e.g after multiple redeployments when the old classloader of the webapp can't be cleared up by the garbage collector (someone might still hold a reference to it). threads.cfg Checks for threads, i.e. checking for the tread count increase rate. A check for finding out deadlocks (on a JDK 6 VM) is provided, too. jetty.cfg Various checks for jetty like checking for running servlets, thread count within the app server, sessions (number and lifing time) or requests per minute. tomcat.cfg Mostly the same checks as for jetty, but for tomcat as application server. websphere.cfg WebSphere specific checks, which uses the configuration files below the `websphere/` directory. For this checks to work, a customized Jolokia agent with JSR-77 extensions is required. The GitHub project for this enhanced agents can be found at <https://github.com/rhuss/jolokia-extra> and downloaded at Maven Central (<http://central.maven.org/maven2/org/jolokia/extra/jolokia-extra-war/>) LICENSEThis 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/>. AUTHORroland@cpan.org
Visit the GSP FreeBSD Man Page Interface. |