Class JMXJsonServlet
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
This servlet generally will be placed under the /jmx URL for each HttpServer. It provides read
only access to JMX metrics. The optional qry parameter may be used to query only a
subset of the JMX Beans. This query functionality is provided through the
MBeanServer.queryNames(ObjectName, javax.management.QueryExp) method.
For example http://.../jmx?qry=Hadoop:* will return all hadoop metrics exposed
through JMX.
The optional get parameter is used to query an specific attribute of a JMX bean. The
format of the URL is http://.../jmx?get=MXBeanName::AttributeName
For example
http://../jmx?get=Hadoop:service=NameNode,name=NameNodeInfo::ClusterId
will return the cluster id of the namenode mxbean.
If we are not sure on the exact attribute and we want to get all the attributes that match one or
more given pattern then the format is
http://.../jmx?get=MXBeanName::*[RegExp1],*[RegExp2]
For example
http://../jmx?get=Hadoop:service=HBase,name=RegionServer,sub=Tables::[a-zA-z_0-9]*memStoreSize
http://../jmx?get=Hadoop:service=HBase,name=RegionServer,sub=Tables::[a-zA-z_0-9]*memStoreSize,[a-zA-z_0-9]*storeFileSize
qry or the get parameter is not formatted correctly then a 400
BAD REQUEST http response code will be returned.
If a resouce such as a mbean or attribute can not be found, a 404 SC_NOT_FOUND http response code will be returned.
The return format is JSON and in the form
{
"beans" : [
{
"name":"bean-name"
...
}
]
}
The servlet attempts to convert the the JMXBeans into JSON. Each bean's attributes will be
converted to a JSON object member. If the attribute is a boolean, a number, a string, or an array
it will be converted to the JSON equivalent. If the value is a CompositeData then it will
be converted to a JSON object with the keys as the name of the JSON member and the value is
converted following these same rules. If the value is a TabularData then it will be
converted to an array of the CompositeData elements that it contains. All other objects
will be converted to a string and output as such. The bean's name and modelerType will be
returned for all beans. Optional paramater "callback" should be used to deliver JSONP response.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final StringIf query string includes 'description', then we will emit bean and attribute descriptions to output IFF they are not null and IFF the description is not the same as the attribute name: i.e.protected JSONBeanprivate static final org.slf4j.Loggerprotected MBeanServerMBean server.private static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringcheckCallbackName(String callbackName) Verifies that the callback property, if provided, is purely alphanumeric.voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Process a GET request for the specified resource.voidinit()Initialize this servlet.Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, serviceMethods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
LOG
-
serialVersionUID
- See Also:
-
CALLBACK_PARAM
- See Also:
-
INCLUDE_DESCRIPTION
If query string includes 'description', then we will emit bean and attribute descriptions to output IFF they are not null and IFF the description is not the same as the attribute name: i.e. specify a URL like so: /jmx?description=true- See Also:
-
mBeanServer
MBean server. -
jsonBeanWriter
-
-
Constructor Details
-
JMXJsonServlet
public JMXJsonServlet()
-
-
Method Details
-
init
Initialize this servlet.- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException Process a GET request for the specified resource. The servlet request we are processing The servlet response we are creating- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
IOException
-
checkCallbackName
Verifies that the callback property, if provided, is purely alphanumeric. This prevents a malicious callback name (that is javascript code) from being returned by the UI to an unsuspecting user.- Parameters:
callbackName- The callback name, can be null.- Returns:
- The callback name
- Throws:
IOException- If the name is disallowed.
-