use of javax.management.AttributeList in project hadoop by apache.
the class MetricsLoggerTask method run.
/**
* Write metrics to the metrics appender when invoked.
*/
@Override
public void run() {
// Skip querying metrics if there are no known appenders.
if (!metricsLog.isInfoEnabled() || !hasAppenders(metricsLog) || objectName == null) {
return;
}
metricsLog.info(" >> Begin " + nodeName + " metrics dump");
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
// Iterate over each MBean.
for (final ObjectName mbeanName : server.queryNames(objectName, null)) {
try {
MBeanInfo mBeanInfo = server.getMBeanInfo(mbeanName);
final String mBeanNameName = MBeans.getMbeanNameName(mbeanName);
final Set<String> attributeNames = getFilteredAttributes(mBeanInfo);
final AttributeList attributes = server.getAttributes(mbeanName, attributeNames.toArray(new String[attributeNames.size()]));
for (Object o : attributes) {
final Attribute attribute = (Attribute) o;
final Object value = attribute.getValue();
final String valueStr = (value != null) ? value.toString() : "null";
// Truncate the value if it is too long
metricsLog.info(mBeanNameName + ":" + attribute.getName() + "=" + trimLine(valueStr));
}
} catch (Exception e) {
metricsLog.error("Failed to get " + nodeName + " metrics for mbean " + mbeanName.toString(), e);
}
}
metricsLog.info(" << End " + nodeName + " metrics dump");
}
use of javax.management.AttributeList in project meteo by pierre.
the class JMXSubscriber method subscribe.
@Override
public void subscribe() {
try {
connect();
} catch (IOException e) {
// ignored
return;
}
this.worker = Executors.newScheduledThreadPool(1).scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
final AttributeList attrList;
try {
attrList = mbeanConn.getAttributes(mbeanName, attrNames);
final LinkedHashMap<String, Object> data = new LinkedHashMap<String, Object>();
log.debug(String.format("Found %d data points", attrList.size()));
for (Object attrObj : attrList) {
Attribute attr = (Attribute) attrObj;
data.put(attr.getName(), attr.getValue());
}
log.debug("Received a message, yay!\n" + data);
esperSink.getEPRuntime().sendEvent(data, jmxConfig.getEventOutputName());
} catch (InstanceNotFoundException ex) {
log.error("Could not fetch from JMX", ex);
} catch (ReflectionException ex) {
log.error("Could not fetch from JMX", ex);
} catch (IOException ex) {
log.error("Could not fetch from JMX", ex);
}
}
}, 0, jmxConfig.getPollIntervalInMillis(), TimeUnit.MILLISECONDS);
}
use of javax.management.AttributeList in project CloudStack-archive by CloudStack-extras.
the class PropertyMapDynamicBean method setAttributes.
@Override
public synchronized AttributeList setAttributes(AttributeList list) {
Attribute[] attrs = (Attribute[]) list.toArray(new Attribute[0]);
AttributeList retList = new AttributeList();
for (Attribute attr : attrs) {
String name = attr.getName();
Object value = attr.getValue();
_propMap.put(name, value);
retList.add(new Attribute(name, value));
}
return retList;
}
use of javax.management.AttributeList in project opennms by OpenNMS.
the class DefaultJmxCollector method getAttributes.
/**
* Get a list of jmx Attributes from the JMX Server.
* The returned list only contains available attributes.
* The input list contains all attributes we would like to fetch.
*
* @return the list of attributes available at the JMX Server.
*/
private List<Attribute> getAttributes(MBeanServerConnection concreteConnection, ObjectName eachObjectName, List<String> attributes) throws InstanceNotFoundException, IOException, ReflectionException {
AttributeList attributeList = concreteConnection.getAttributes(eachObjectName, attributes.toArray(new String[attributes.size()]));
List<Attribute> newList = new ArrayList<>();
for (Object eachObject : attributeList) {
if (eachObject instanceof Attribute) {
newList.add((Attribute) eachObject);
}
}
return Collections.checkedList(newList, Attribute.class);
}
use of javax.management.AttributeList in project intellij-community by JetBrains.
the class CpuTimings method getSystemCpuLoad.
public static double getSystemCpuLoad() {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
AttributeList list = mbs.getAttributes(name, new String[] { "SystemCpuLoad" });
if (list.isEmpty())
return Double.NaN;
Attribute att = (Attribute) list.get(0);
Double value = (Double) att.getValue();
// usually takes a couple of seconds before we get real values
if (value == -1.0)
return Double.NaN;
// returns a percentage value with 1 decimal point precision
return ((int) (value * 1000) / 10.0);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations