JMX::Jmx4Perl::Agent - JSON-HTTP based acess to a remote JMX agent


 my $agent = new JMX::Jmx4Perl(mode=>"agent", url => "http://jeeserver/j4p");
 my $answer = $agent->get_attribute("java.lang:type=Memory","HeapMemoryUsage");
 print Dumper($answer);

   request => {
     attribute => "HeapMemoryUsage",
     name => "java.lang:type=Memory"
   status => 200,
   value => {
     committed => 18292736,
     init => 0,
     max => 532742144,
     used => 15348352


This module is not used directly, but via JMX::Jmx4Perl, which acts as a proxy to this module. You can think of JMX::Jmx4Perl as the interface which is backed up by this module. Other implementations (e.g.


$jjagent = JMX::Jmx4Perl::Agent->new(url => $url, ....)

Creates a new local agent for a given url

url => <url to JEE server>

The url where the agent is deployed. This is a mandatory parameter. The url must include the context within the server, which is typically based on the name of the war archive. Example: http://localhost:8080/j4p for a drop in deployment of the agent in a standard Tomcat's webapp directory.

timeout => <timeout>

Timeout in seconds after which a request should be stopped if it not suceeds within this time. This parameter is given through directly to the underlying LWP::UserAgent

user => <user>, password => <password>

Credentials to use for the HTTP request

method => <method>

The HTTP method to use for contacting the agent. Must be either "GET" or "POST". This method is used, if the request to send dosen't specify the method and no other parameters forces a POST context.

proxy => { http => '<http_proxy>', https => '<https_proxy>', ... }
proxy => <http_proxy>
proxy => { url => <http_proxy> }

Optional proxy to use

proxy_user => <user>, proxy_password => <password>

Credentials to use for accessing the proxy


Add a target which is used for any request served by this object if not already a target is present in the request. This way you can setup the default target configuration if you are using the agent servlet as a proxy, e.g.

  ... target => { url => "service:jmx:...", user => "...", password => "..." }

Before version 1.0 a quite strange escaping scheme is used, when the part of a GET requests contains a slash (/). Starting with 1.0 this scheme has changed, but in order to allow post 1.0 Jmx4perl clients acess pre 1.0 Jolokia agents, this option can be set to true to switch to the old escape mechanism.

$url = $agent->url()

Get the base URL for connecting to the agent. You cannot change the URL via this method, it is immutable for a given agent.

$resp = $agent->request($request)

Implementation of the JMX request as specified in JMX::Jmx4Perl. It uses a HTTP::Request sent via an LWP::UserAgent for posting a JSON representation of the request. This method shouldn't be called directly but via JMX::Jmx4Perl->request().

$encrypted = $agent->encrypt($plain)

Encrypt a password which can be used in configuration files in order to obfuscate the clear text password.

$url = $agent->request_url($request)

Generate the URL for accessing the java agent based on a given request.


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 <>.

A commercial license is available as well. Please contact for further details.