use of javax.management.MBeanAttributeInfo in project hive by apache.
the class MetricsMBeanImpl method getMBeanInfo.
@Override
public MBeanInfo getMBeanInfo() {
if (dirtyAttributeInfoCache) {
synchronized (metricsMap) {
attributeInfos = new MBeanAttributeInfo[metricsMap.size()];
int i = 0;
for (String key : metricsMap.keySet()) {
attributeInfos[i] = new MBeanAttributeInfo(key, metricsMap.get(key).getClass().getName(), key, true, true, /*writable*/
false);
i++;
}
dirtyAttributeInfoCache = false;
}
}
return new MBeanInfo(this.getClass().getName(), "metrics information", attributeInfos, ctors, ops, notifs);
}
use of javax.management.MBeanAttributeInfo in project tomcat by apache.
the class JMXAccessorQueryTask method bindAttributes.
protected void bindAttributes(MBeanServerConnection jmxServerConnection, String pname, ObjectName oname) {
try {
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
MBeanAttributeInfo[] attrs = minfo.getAttributes();
Object value = null;
for (int i = 0; i < attrs.length; i++) {
if (!attrs[i].isReadable())
continue;
String attName = attrs[i].getName();
if (attName.indexOf('=') >= 0 || attName.indexOf(':') >= 0 || attName.indexOf(' ') >= 0) {
continue;
}
try {
value = jmxServerConnection.getAttribute(oname, attName);
} catch (Exception e) {
if (isEcho())
handleErrorOutput("Error getting attribute " + oname + " " + pname + attName + " " + e.toString());
continue;
}
if (value == null)
continue;
if ("modelerType".equals(attName))
continue;
createProperty(pname + attName, value);
}
} catch (Exception e) {
// Ignore
}
}
use of javax.management.MBeanAttributeInfo in project tomcat by apache.
the class JMXAccessorSetTask method getMBeanAttributeType.
/**
* Get MBean Attribute from Mbean Server
*
* @param jmxServerConnection The JMX connection name
* @param name The MBean name
* @param attribute The attribute name
* @return The type of the attribute
* @throws Exception An error occurred
*/
protected String getMBeanAttributeType(MBeanServerConnection jmxServerConnection, String name, String attribute) throws Exception {
ObjectName oname = new ObjectName(name);
String mattrType = null;
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
MBeanAttributeInfo[] attrs = minfo.getAttributes();
for (int i = 0; mattrType == null && i < attrs.length; i++) {
if (attribute.equals(attrs[i].getName()))
mattrType = attrs[i].getType();
}
return mattrType;
}
use of javax.management.MBeanAttributeInfo in project jcollectd by collectd.
the class MBeanCollector method collect.
public void collect(MBeanQuery query, ObjectName name) throws Exception {
MBeanServerConnection conn = _sender.getMBeanServerConnection();
String plugin = query.getPlugin();
if (plugin == null) {
plugin = name.getDomain();
}
Map<String, MBeanAttributeInfo> attrInfo = null;
if (_useDescriptors) {
MBeanInfo info = conn.getMBeanInfo(name);
attrInfo = new HashMap<String, MBeanAttributeInfo>();
for (MBeanAttributeInfo ainfo : info.getAttributes()) {
attrInfo.put(ainfo.getName(), ainfo);
}
}
for (MBeanAttribute attr : query.getAttributes()) {
String attrName = attr.getAttributeName();
Object obj;
try {
obj = conn.getAttribute(name, attrName);
} catch (Exception e) {
//XXX remove attr for future collection e.g. UnsupportedOperation
continue;
}
if (_useDescriptors) {
//e.g. spring @ManagedMetric(metricType = MetricType.COUNTER)
try {
Descriptor descriptor = (Descriptor) _getDescriptor.invoke(attrInfo.get(attrName), (Object[]) null);
Object type = descriptor.getFieldValue(_metricTypeField);
if (TypesDB.NAME_COUNTER.equals(type)) {
if (attr.getTypeName().equals(TypesDB.NAME_GAUGE)) {
attr.setTypeName(TypesDB.NAME_COUNTER);
}
attr.setDataType(Network.DS_TYPE_COUNTER);
}
} catch (Exception e) {
}
}
if (obj instanceof CompositeData) {
CompositeData data = (CompositeData) obj;
String key = attr.getCompositeKey();
if (key == null) {
//no key specified; collect all
Set<String> keys = data.getCompositeType().keySet();
for (String ckey : keys) {
obj = data.get(ckey);
if (!isNumber(obj)) {
continue;
}
dispatch(query, plugin, attrName + "." + ckey, name, attr, (Number) obj);
}
continue;
} else {
obj = data.get(key);
}
}
if (!isNumber(obj)) {
continue;
}
dispatch(query, plugin, attr.getName(), name, attr, (Number) obj);
}
_sender.flush();
}
use of javax.management.MBeanAttributeInfo in project jcollectd by collectd.
the class MBeanCollector method queryAll.
private MBeanQuery queryAll(ObjectName name) throws Exception {
MBeanQuery query = new MBeanQuery(name);
MBeanInfo info = _sender.getMBeanServerConnection().getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
for (int i = 0; i < attrs.length; i++) {
query.addAttribute(new MBeanAttribute(attrs[i].getName()));
}
return query;
}
Aggregations