Class JMXJsonServlet
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
- Direct Known Subclasses:
JMXJsonServletNaNFiltered
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 the 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.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.fasterxml.jackson.core.JsonFactoryJson Factory to create Json generators for write objects in json formatprotected MBeanServerMBean server. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Process a GET request for the specified resource.protected voiddoTrace(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Disable TRACE method to avoid TRACE vulnerability.protected booleanextraCheck(Object value) In case you need to modify the logic, how java objects transforms to json, you can overwrite this method to return true in case special handlingprotected voidextraWrite(Object value, String attName, com.fasterxml.jackson.core.JsonGenerator jg) voidinit()Initialize this servlet.protected booleanisInstrumentationAccessAllowed(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, getLastModified, service, serviceMethods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
mBeanServer
MBean server. -
jsonFactory
protected transient com.fasterxml.jackson.core.JsonFactory jsonFactoryJson Factory to create Json generators for write objects in json format
-
-
Constructor Details
-
JMXJsonServlet
public JMXJsonServlet()
-
-
Method Details
-
init
public void init() throws javax.servlet.ServletExceptionInitialize this servlet.- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
isInstrumentationAccessAllowed
protected boolean isInstrumentationAccessAllowed(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException - Throws:
IOException
-
doTrace
protected void doTrace(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException Disable TRACE method to avoid TRACE vulnerability.- Overrides:
doTracein classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Process a GET request for the specified resource.- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creating
-
extraCheck
In case you need to modify the logic, how java objects transforms to json, you can overwrite this method to return true in case special handling- Parameters:
value- the object what should be judged- Returns:
- true, if it needs special transformation
-
extraWrite
protected void extraWrite(Object value, String attName, com.fasterxml.jackson.core.JsonGenerator jg) throws IOException - Throws:
IOException
-