HBASE-26554 Introduce a new parameter in jmx servlet to exclude the specific mbean (#3930)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
a3ff8e4c81
commit
136b1ea7ab
|
@ -212,7 +212,11 @@ public class JMXJsonServlet extends HttpServlet {
|
|||
if (qry == null) {
|
||||
qry = "*:*";
|
||||
}
|
||||
if (beanWriter.write(this.mBeanServer, new ObjectName(qry), null, description) != 0) {
|
||||
String excl = request.getParameter("excl");
|
||||
ObjectName excluded = excl == null ? null : new ObjectName(excl);
|
||||
|
||||
if (beanWriter.write(this.mBeanServer, new ObjectName(qry),
|
||||
null, description, excluded) != 0) {
|
||||
beanWriter.flush();
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
|
|
|
@ -66,8 +66,13 @@ public class JSONBean {
|
|||
|
||||
void write(String key, String value) throws IOException;
|
||||
|
||||
int write(MBeanServer mBeanServer, ObjectName qry, String attribute, boolean description)
|
||||
throws IOException;
|
||||
default int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
|
||||
boolean description) throws IOException {
|
||||
return write(mBeanServer, qry, attribute, description, null);
|
||||
}
|
||||
|
||||
int write(MBeanServer mBeanServer, ObjectName qry, String attribute, boolean description,
|
||||
ObjectName excluded) throws IOException;
|
||||
|
||||
void flush() throws IOException;
|
||||
}
|
||||
|
@ -118,8 +123,8 @@ public class JSONBean {
|
|||
|
||||
@Override
|
||||
public int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
|
||||
boolean description) throws IOException {
|
||||
return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description);
|
||||
boolean description, ObjectName excluded) throws IOException {
|
||||
return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description, excluded);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -128,7 +133,7 @@ public class JSONBean {
|
|||
* @return Return non-zero if failed to find bean. 0
|
||||
*/
|
||||
private static int write(JsonWriter writer, MBeanServer mBeanServer, ObjectName qry,
|
||||
String attribute, boolean description) throws IOException {
|
||||
String attribute, boolean description, ObjectName excluded) throws IOException {
|
||||
LOG.debug("Listing beans for {}", qry);
|
||||
Set<ObjectName> names = null;
|
||||
names = mBeanServer.queryNames(qry, null);
|
||||
|
@ -137,6 +142,9 @@ public class JSONBean {
|
|||
Pattern[] matchingPattern = null;
|
||||
while (it.hasNext()) {
|
||||
ObjectName oname = it.next();
|
||||
if (excluded != null && excluded.apply(oname)) {
|
||||
continue;
|
||||
}
|
||||
MBeanInfo minfo;
|
||||
String code = "";
|
||||
String descriptionStr = null;
|
||||
|
|
|
@ -122,6 +122,12 @@ public class TestJMXJsonServlet extends HttpServerFunctionalTest {
|
|||
assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result);
|
||||
assertReFind("\"committed\"\\s*:", result);
|
||||
assertReFind("\\}\\);$", result);
|
||||
|
||||
// test exclude the specific mbean
|
||||
result = readOutput(new URL(baseUrl,
|
||||
"/jmx?excl=Hadoop:service=HBase,name=RegionServer,sub=Regions"));
|
||||
LOG.info("/jmx RESULT: " + result);
|
||||
assertNotFind("\"name\"\\s*:\\s*\"Hadoop:service=HBase,name=RegionServer,sub=Regions\"",result);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue