use of javax.management.MBeanAttributeInfo in project tomee by apache.
the class EjbdJmxTest method test.
@Test
public void test() throws Exception {
System.setProperty("openejb.jmx.active", "true");
final MBeanServer server = LocalMBeanServer.get();
OpenEJB.init(new Properties());
final Properties p = new Properties();
p.put("server", "org.apache.openejb.server.ejbd.EjbServer");
p.put("bind", "127.0.0.1");
p.put("port", "0");
p.put("disabled", "false");
p.put("threads", "10");
p.put("backlog", "200");
p.put("discovery", "ejb:ejbd://{bind}:{port}");
final ServerService service = ServiceManager.manage("ejbd", p, new EjbServer());
service.init(p);
service.start();
ServiceManager.register("ejbd", service, server);
ObjectName invocationsName = new ObjectName("openejb:type=ServerService,name=ejbd");
MBeanInfo beanInfo = server.getMBeanInfo(invocationsName);
for (MBeanAttributeInfo info : beanInfo.getAttributes()) {
System.out.println(info);
}
service.stop();
OpenEJB.destroy();
}
use of javax.management.MBeanAttributeInfo in project cdap by caskdata.
the class OperationalStatsHttpHandler method getStats.
/**
* Reads operational stats collected using the {@link OperationalStats} extension mechanism with the specified
* property key and value, grouped by the specified groupByKey.
*
* @param propertyKey the key that must be contained with the specified value in the stat to be returned
* @param propertyValue the value that the specified key must have in the stat to be returned
* @param groupByKey an additional key in the stat's property to group the stats by
* @return a {@link Map} of the group to a {@link Map} of stats of that group
* @throws Exception when there are errors reading stats using JMX
*/
@VisibleForTesting
Map<String, Map<String, Object>> getStats(String propertyKey, String propertyValue, String groupByKey) throws Exception {
Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey), "Property should not be null or empty.");
Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyValue), "Property value should not be null or empty.");
Hashtable<String, String> properties = new Hashtable<>();
// we want stats with the specified value for the specified key, so set them in the properties
properties.put(propertyKey, propertyValue);
// since we want to group by the groupKey, we want to fetch all groups
properties.put(groupByKey, "*");
ObjectName objectName = new ObjectName(OperationalStatsUtils.JMX_DOMAIN, properties);
Map<String, Map<String, Object>> result = new HashMap<>();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (ObjectName name : mbs.queryNames(objectName, null)) {
String group = name.getKeyProperty(groupByKey);
MBeanInfo mBeanInfo = mbs.getMBeanInfo(name);
Map<String, Object> stats = new HashMap<>();
for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
stats.put(attributeInfo.getName(), mbs.getAttribute(name, attributeInfo.getName()));
}
result.put(group, stats);
LOG.trace("Found stats of group {} as {}", group, stats);
}
return result;
}
use of javax.management.MBeanAttributeInfo in project hbase by apache.
the class TestStochasticBalancerJmxMetrics method readJmxMetrics.
/**
* Read the attributes from Hadoop->HBase->Master->Balancer in JMX
* @throws IOException
*/
private Set<String> readJmxMetrics() throws IOException {
JMXConnector connector = null;
ObjectName target = null;
MBeanServerConnection mb = null;
try {
connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));
mb = connector.getMBeanServerConnection();
Hashtable<String, String> pairs = new Hashtable<>();
pairs.put("service", "HBase");
pairs.put("name", "Master");
pairs.put("sub", "Balancer");
target = new ObjectName("Hadoop", pairs);
MBeanInfo beanInfo = mb.getMBeanInfo(target);
Set<String> existingAttrs = new HashSet<>();
for (MBeanAttributeInfo attrInfo : beanInfo.getAttributes()) {
existingAttrs.add(attrInfo.getName());
}
return existingAttrs;
} catch (Exception e) {
LOG.warn("Failed to get bean!!! " + target, e);
if (mb != null) {
Set<ObjectInstance> instances = mb.queryMBeans(null, null);
Iterator<ObjectInstance> iterator = instances.iterator();
System.out.println("MBean Found:");
while (iterator.hasNext()) {
ObjectInstance instance = iterator.next();
System.out.println("Class Name: " + instance.getClassName());
System.out.println("Object Name: " + instance.getObjectName());
}
}
} finally {
if (connector != null) {
try {
connector.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return null;
}
use of javax.management.MBeanAttributeInfo in project flink by apache.
the class JMXReporterTest method testHistogramReporting.
/**
* Tests that histograms are properly reported via the JMXReporter.
*/
@Test
public void testHistogramReporting() throws Exception {
MetricRegistry registry = null;
String histogramName = "histogram";
try {
Configuration config = new Configuration();
config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "jmx_test");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "jmx_test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
TestingHistogram histogram = new TestingHistogram();
metricGroup.histogram(histogramName, histogram);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + histogramName, JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
MBeanAttributeInfo[] attributeInfos = info.getAttributes();
assertEquals(11, attributeInfos.length);
assertEquals(histogram.getCount(), mBeanServer.getAttribute(objectName, "Count"));
assertEquals(histogram.getStatistics().getMean(), mBeanServer.getAttribute(objectName, "Mean"));
assertEquals(histogram.getStatistics().getStdDev(), mBeanServer.getAttribute(objectName, "StdDev"));
assertEquals(histogram.getStatistics().getMax(), mBeanServer.getAttribute(objectName, "Max"));
assertEquals(histogram.getStatistics().getMin(), mBeanServer.getAttribute(objectName, "Min"));
assertEquals(histogram.getStatistics().getQuantile(0.5), mBeanServer.getAttribute(objectName, "Median"));
assertEquals(histogram.getStatistics().getQuantile(0.75), mBeanServer.getAttribute(objectName, "75thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.95), mBeanServer.getAttribute(objectName, "95thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.98), mBeanServer.getAttribute(objectName, "98thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.99), mBeanServer.getAttribute(objectName, "99thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.999), mBeanServer.getAttribute(objectName, "999thPercentile"));
} finally {
if (registry != null) {
registry.shutdown();
}
}
}
use of javax.management.MBeanAttributeInfo in project tomcat by apache.
the class Registry method getType.
// -------------------- Helpers --------------------
/**
* Get the type of an attribute of the object, from the metadata.
*
* @param oname The bean name
* @param attName The attribute name
* @return null if metadata about the attribute is not found
* @since 1.1
*/
public String getType(ObjectName oname, String attName) {
String type = null;
MBeanInfo info = null;
try {
info = server.getMBeanInfo(oname);
} catch (Exception e) {
log.info("Can't find metadata for object" + oname);
return null;
}
MBeanAttributeInfo[] attInfo = info.getAttributes();
for (int i = 0; i < attInfo.length; i++) {
if (attName.equals(attInfo[i].getName())) {
type = attInfo[i].getType();
return type;
}
}
return null;
}
Aggregations