use of javax.management.MalformedObjectNameException in project jetty.project by eclipse.
the class JavaMonitorAction method parseResponse.
/* ------------------------------------------------------------ */
private void parseResponse(Properties response) {
if (response.get("onhold") != null)
throw new Error("Suspended");
if (response.get("session") != null) {
_session = (String) response.remove("session");
AggregateEventTrigger trigger = (AggregateEventTrigger) getTrigger();
String queryString;
ObjectName[] queryResults;
for (Map.Entry<Object, Object> entry : response.entrySet()) {
String[] values = ((String) entry.getValue()).split("\\|");
queryString = values[0];
if (queryString.startsWith("com.javamonitor.openfire"))
continue;
if (queryString.startsWith("com.javamonitor")) {
queryString = "org.eclipse.jetty.monitor.integration:type=javamonitortools,id=0";
}
queryResults = null;
try {
queryResults = queryNames(queryString);
} catch (IOException e) {
LOG.debug(e);
} catch (MalformedObjectNameException e) {
LOG.debug(e);
}
if (queryResults != null) {
int idx = 0;
for (ObjectName objName : queryResults) {
String id = entry.getKey().toString() + (idx == 0 ? "" : ":" + idx);
String name = queryString.equals(objName.toString()) ? "" : objName.toString();
boolean repeat = Boolean.parseBoolean(values[2]);
trigger.add(new JavaMonitorTrigger(objName, values[1], id, name, repeat));
}
}
}
}
}
use of javax.management.MalformedObjectNameException in project tomcat by apache.
the class MemoryUserDatabaseMBean method findUser.
/**
* Return the MBean Name for the specified user name (if any);
* otherwise return <code>null</code>.
*
* @param username User name to look up
* @return the user object name
*/
public String findUser(String username) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
if (user == null) {
return null;
}
try {
ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user);
return oname.toString();
} catch (MalformedObjectNameException e) {
IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for user [" + username + "]");
iae.initCause(e);
throw iae;
}
}
use of javax.management.MalformedObjectNameException in project tomcat by apache.
the class BaseGenericObjectPool method jmxRegister.
/**
* Registers the pool with the platform MBean server.
* The registered name will be
* <code>jmxNameBase + jmxNamePrefix + i</code> where i is the least
* integer greater than or equal to 1 such that the name is not already
* registered. Swallows MBeanRegistrationException, NotCompliantMBeanException
* returning null.
*
* @param config Pool configuration
* @param jmxNameBase default base JMX name for this pool
* @param jmxNamePrefix name prefix
* @return registered ObjectName, null if registration fails
*/
private ObjectName jmxRegister(final BaseObjectPoolConfig config, final String jmxNameBase, String jmxNamePrefix) {
ObjectName objectName = null;
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
int i = 1;
boolean registered = false;
String base = config.getJmxNameBase();
if (base == null) {
base = jmxNameBase;
}
while (!registered) {
try {
ObjectName objName;
// only one so the names are cleaner.
if (i == 1) {
objName = new ObjectName(base + jmxNamePrefix);
} else {
objName = new ObjectName(base + jmxNamePrefix + i);
}
mbs.registerMBean(this, objName);
objectName = objName;
registered = true;
} catch (final MalformedObjectNameException e) {
if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(jmxNamePrefix) && jmxNameBase.equals(base)) {
// Shouldn't happen. Skip registration if it does.
registered = true;
} else {
// Must be an invalid name. Use the defaults instead.
jmxNamePrefix = BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
base = jmxNameBase;
}
} catch (final InstanceAlreadyExistsException e) {
// Increment the index and try again
i++;
} catch (final MBeanRegistrationException e) {
// Shouldn't happen. Skip registration if it does.
registered = true;
} catch (final NotCompliantMBeanException e) {
// Shouldn't happen. Skip registration if it does.
registered = true;
}
}
return objectName;
}
use of javax.management.MalformedObjectNameException in project hadoop by apache.
the class JMXJsonServlet method doGet.
/**
* Process a GET request for the specified resource.
*
* @param request
* The servlet request we are processing
* @param response
* The servlet response we are creating
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
// If user is a static user and auth Type is null, that means
// there is a non-security environment and no need authorization,
// otherwise, do the authorization.
final ServletContext servletContext = getServletContext();
if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) && !isInstrumentationAccessAllowed(request, response)) {
return;
}
JsonGenerator jg = null;
PrintWriter writer = null;
try {
writer = response.getWriter();
response.setContentType("application/json; charset=utf8");
response.setHeader(ACCESS_CONTROL_ALLOW_METHODS, "GET");
response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
jg = jsonFactory.createGenerator(writer);
jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
jg.useDefaultPrettyPrinter();
jg.writeStartObject();
// query per mbean attribute
String getmethod = request.getParameter("get");
if (getmethod != null) {
String[] splitStrings = getmethod.split("\\:\\:");
if (splitStrings.length != 2) {
jg.writeStringField("result", "ERROR");
jg.writeStringField("message", "query format is not as expected.");
jg.flush();
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
listBeans(jg, new ObjectName(splitStrings[0]), splitStrings[1], response);
return;
}
// query per mbean
String qry = request.getParameter("qry");
if (qry == null) {
qry = "*:*";
}
listBeans(jg, new ObjectName(qry), null, response);
} finally {
if (jg != null) {
jg.close();
}
if (writer != null) {
writer.close();
}
}
} catch (IOException e) {
LOG.error("Caught an exception while processing JMX request", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch (MalformedObjectNameException e) {
LOG.error("Caught an exception while processing JMX request", e);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
use of javax.management.MalformedObjectNameException in project flink by apache.
the class TaskExecutorMetricsInitializer method instantiateMemoryMetrics.
private static void instantiateMemoryMetrics(MetricGroup metrics) {
final MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
MetricGroup heap = metrics.addGroup("Heap");
heap.<Long, Gauge<Long>>gauge("Used", new Gauge<Long>() {
@Override
public Long getValue() {
return mxBean.getHeapMemoryUsage().getUsed();
}
});
heap.<Long, Gauge<Long>>gauge("Committed", new Gauge<Long>() {
@Override
public Long getValue() {
return mxBean.getHeapMemoryUsage().getCommitted();
}
});
heap.<Long, Gauge<Long>>gauge("Max", new Gauge<Long>() {
@Override
public Long getValue() {
return mxBean.getHeapMemoryUsage().getMax();
}
});
MetricGroup nonHeap = metrics.addGroup("NonHeap");
nonHeap.<Long, Gauge<Long>>gauge("Used", new Gauge<Long>() {
@Override
public Long getValue() {
return mxBean.getNonHeapMemoryUsage().getUsed();
}
});
nonHeap.<Long, Gauge<Long>>gauge("Committed", new Gauge<Long>() {
@Override
public Long getValue() {
return mxBean.getNonHeapMemoryUsage().getCommitted();
}
});
nonHeap.<Long, Gauge<Long>>gauge("Max", new Gauge<Long>() {
@Override
public Long getValue() {
return mxBean.getNonHeapMemoryUsage().getMax();
}
});
final MBeanServer con = ManagementFactory.getPlatformMBeanServer();
final String directBufferPoolName = "java.nio:type=BufferPool,name=direct";
try {
final ObjectName directObjectName = new ObjectName(directBufferPoolName);
MetricGroup direct = metrics.addGroup("Direct");
direct.<Long, Gauge<Long>>gauge("Count", new TaskExecutorMetricsInitializer.AttributeGauge<>(con, directObjectName, "Count", -1L));
direct.<Long, Gauge<Long>>gauge("MemoryUsed", new TaskExecutorMetricsInitializer.AttributeGauge<>(con, directObjectName, "MemoryUsed", -1L));
direct.<Long, Gauge<Long>>gauge("TotalCapacity", new TaskExecutorMetricsInitializer.AttributeGauge<>(con, directObjectName, "TotalCapacity", -1L));
} catch (MalformedObjectNameException e) {
LOG.warn("Could not create object name {}.", directBufferPoolName, e);
}
final String mappedBufferPoolName = "java.nio:type=BufferPool,name=mapped";
try {
final ObjectName mappedObjectName = new ObjectName(mappedBufferPoolName);
MetricGroup mapped = metrics.addGroup("Mapped");
mapped.<Long, Gauge<Long>>gauge("Count", new TaskExecutorMetricsInitializer.AttributeGauge<>(con, mappedObjectName, "Count", -1L));
mapped.<Long, Gauge<Long>>gauge("MemoryUsed", new TaskExecutorMetricsInitializer.AttributeGauge<>(con, mappedObjectName, "MemoryUsed", -1L));
mapped.<Long, Gauge<Long>>gauge("TotalCapacity", new TaskExecutorMetricsInitializer.AttributeGauge<>(con, mappedObjectName, "TotalCapacity", -1L));
} catch (MalformedObjectNameException e) {
LOG.warn("Could not create object name {}.", mappedBufferPoolName, e);
}
}
Aggregations