public static double getProcessCpuLoad() throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem"); AttributeList list = mbs.getAttributes(name, new String[]{ "ProcessCpuLoad" }); 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); }
if (attributes.isEmpty()) return resultList;
} else if (result instanceof AttributeList) { AttributeList list = (AttributeList) result; if (list.isEmpty()) { result = null; } else {
if (attributes.isEmpty()) { return resultList;
@Override public final double getCpuLevel() throws InstanceNotFoundException, ReflectionException { // This method will block until CPU usage is low enough AttributeList list = mbs.getAttributes(osBeanName, new String[]{"ProcessCpuLoad"}); if (list.isEmpty()) { LOG.error("No CPU stats found for ProcessCpuLoad"); return -1; } Attribute att = (Attribute) list.get(0); return (Double) att.getValue(); }
@Override public final double getCpuLevel() throws InstanceNotFoundException, ReflectionException { // This method will block until CPU usage is low enough AttributeList list = mbs.getAttributes(osBeanName, new String[]{"ProcessCpuLoad"}); if (list.isEmpty()) { LOG.error("No CPU stats found for ProcessCpuLoad"); return -1; } Attribute att = (Attribute) list.get(0); return (Double) att.getValue(); }
public static double getProcessCpuLoad(MBeanServerConnection mbs) throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException, ReflectionException, IOException { ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem"); AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"}); if (list.isEmpty()) { return 0.0; } 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 0.0; } // returns a percentage value with 1 decimal point precision return ((int) (value * 1000) / 10.0); }
public static double getProcessCpuLoad(MBeanServerConnection mbs) throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException, ReflectionException, IOException { ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem"); AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"}); if (list.isEmpty()) { return 0.0; } 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 0.0; } // returns a percentage value with 1 decimal point precision return ((int) (value * 1000) / 10.0); }
/** * Sets the values of several attributes of the Dynamic MBean, and returns the list of * attributes that have been set. */ public AttributeList setAttributes(AttributeList attributes) { if (attributes == null) throw new RuntimeOperationsException(new IllegalArgumentException( "AttributeList attributes can not be null"), "Can not invoke a setter of " + THIS_CLASS_NAME); AttributeList resultList = new AttributeList(); // if attributeNames is empty, nothing more to do if (attributes.isEmpty()) return resultList; // for each attribute, try to set it and add to the result list if successful for (Iterator i = attributes.iterator(); i.hasNext(); ) { Attribute attr = (Attribute) i.next(); try { setAttribute(attr); String name = attr.getName(); Object value = getAttribute(name); resultList.add(new Attribute(name, value)); } catch (Exception e) { if (_logger.isLoggable(Level.WARNING)) { _logger.log(Level.WARNING, e.toString(), e); } } } return resultList; }
private void getCPULoad(String[] attrib) { try { if (null==os) { return; } AttributeList list = mbs.getAttributes(os, attrib); if (list.isEmpty()) { return; } Double value = (Double)((Attribute)list.get(0)).getValue(); if (value == -1.0) { return; // usually takes a couple of seconds before we get real values } else { long longValue = (long)(ONE_HUNDRED_PERCENT * value.doubleValue()); SmallFootprintHistogram.record(that.histogram, longValue); } } catch (Exception e) { log.warn("unable to fetch CPU usage", e); return; } }
private void getCPULoad(String[] attrib) { try { if (null==os) { return; } AttributeList list = mbs.getAttributes(os, attrib); if (list.isEmpty()) { return; } Double value = (Double)((Attribute)list.get(0)).getValue(); if (value == -1.0) { return; // usually takes a couple of seconds before we get real values } else { long longValue = (long)(ONE_HUNDRED_PERCENT * value.doubleValue()); SmallFootprintHistogram.record(that.histogram, longValue); } } catch (Exception e) { log.warn("unable to fetch CPU usage", e); return; } }
private void getCPULoad(String[] attrib) { try { if (null==os) { return; } AttributeList list = mbs.getAttributes(os, attrib); if (list.isEmpty()) { return; } Double value = (Double)((Attribute)list.get(0)).getValue(); if (value == -1.0) { return; // usually takes a couple of seconds before we get real values } else { long longValue = (long)(ONE_HUNDRED_PERCENT * value.doubleValue()); SmallFootprintHistogram.record(that.histogram, longValue); } } catch (Exception e) { log.warn("unable to fetch CPU usage", e); return; } }
if (attributes.isEmpty()) { return resultList;
if (attributes.isEmpty()) return resultList;
if (attributes.isEmpty()) return resultList;
releaseMbeanServerConnection(); cnx = null; if (al.isEmpty()) {
if ( !attribList.isEmpty() )
releaseMbeanServerConnection(); cnx = null; if (al.isEmpty()) {
releaseMbeanServerConnection(); cnx = null; if (al.isEmpty()) {
if ( !attribList.isEmpty() )