Example usage for javax.management ObjectName getKeyPropertyList

List of usage examples for javax.management ObjectName getKeyPropertyList

Introduction

In this page you can find the example usage for javax.management ObjectName getKeyPropertyList.

Prototype


public Hashtable<String, String> getKeyPropertyList() 

Source Link

Document

Returns the key properties as a Hashtable.

Usage

From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java

/**
 * {@inheritDoc}//from   w w w.jav  a 2 s .  c o  m
 * @see com.heliosapm.opentsdb.TSDBSubmitter#trace(javax.management.ObjectName, long)
 */
@Override
public void trace(final ObjectName metric, final long value) {
    if (metric == null || metric.isPattern())
        return;
    trace(time(), metric.getDomain(), value, metric.getKeyPropertyList());
}

From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java

/**
 * {@inheritDoc}/*from w  w  w . ja va 2 s  .com*/
 * @see com.heliosapm.opentsdb.TSDBSubmitter#trace(javax.management.ObjectName, double)
 */
@Override
public void trace(final ObjectName metric, final double value) {
    if (metric == null || metric.isPattern())
        return;
    trace(time(), metric.getDomain(), value, metric.getKeyPropertyList());
}

From source file:com.cyberway.issue.crawler.Heritrix.java

protected static ObjectName addGuiPort(ObjectName name)
        throws MalformedObjectNameException, NullPointerException {
    @SuppressWarnings("unchecked")
    Hashtable<String, String> ht = name.getKeyPropertyList();
    if (!ht.containsKey(JmxUtils.GUI_PORT)) {
        // Add gui port if this instance was started with a gui.
        if (Heritrix.gui) {
            ht.put(JmxUtils.GUI_PORT, Integer.toString(Heritrix.guiPort));
            name = new ObjectName(name.getDomain(), ht);
        }//ww  w  .  j  ava 2s. c  o m
    }
    return name;
}

From source file:com.cyberway.issue.crawler.Heritrix.java

/**
 * Add vital stats to passed in ObjectName.
 * @param name ObjectName to add to.//from   w ww .ja  v a2s .c  om
 * @return name with host, guiport, and jmxport added.
 * @throws UnknownHostException
 * @throws MalformedObjectNameException
 * @throws NullPointerException
 */
protected static ObjectName addVitals(ObjectName name)
        throws UnknownHostException, MalformedObjectNameException, NullPointerException {
    @SuppressWarnings("unchecked")
    Hashtable<String, String> ht = name.getKeyPropertyList();
    if (!ht.containsKey(JmxUtils.HOST)) {
        ht.put(JmxUtils.HOST, InetAddress.getLocalHost().getHostName());
        name = new ObjectName(name.getDomain(), ht);
    }
    if (!ht.containsKey(JmxUtils.JMX_PORT)) {
        // Add jdk jmx-port. This will be present if we've attached
        // ourselves to the jdk jmx agent.  Otherwise, we've been
        // deployed in a j2ee container with its own jmx agent.  In
        // this case we won't know how to get jmx port.
        String p = System.getProperty("com.sun.management.jmxremote.port");
        if (p != null && p.length() > 0) {
            ht.put(JmxUtils.JMX_PORT, p);
            name = new ObjectName(name.getDomain(), ht);
        }
    }
    return name;
}

From source file:com.cyberway.issue.crawler.admin.CrawlJob.java

public ObjectName preRegister(final MBeanServer server, ObjectName on) throws Exception {
    this.mbeanServer = server;
    @SuppressWarnings("unchecked")
    Hashtable<String, String> ht = on.getKeyPropertyList();
    if (!ht.containsKey(JmxUtils.NAME)) {
        throw new IllegalArgumentException("Name property required" + on.getCanonicalName());
    }//  w  w  w.  j a  va 2  s .c  o m
    // Now append key/values from hosting heritrix JMX ObjectName so it can be
    // found just by examination of the CrawlJob JMX ObjectName.  Add heritrix
    // name attribute as 'mother' attribute.
    Heritrix h = getHostingHeritrix();
    if (h == null || h.getMBeanName() == null) {
        throw new IllegalArgumentException(
                "Hosting heritrix not found " + "or not registered with JMX: " + on.getCanonicalName());
    }
    @SuppressWarnings("unchecked")
    Map<String, String> hht = h.getMBeanName().getKeyPropertyList();
    ht.put(JmxUtils.MOTHER, hht.get(JmxUtils.NAME));
    String port = hht.get(JmxUtils.JMX_PORT);
    if (port != null) {
        ht.put(JmxUtils.JMX_PORT, port);
    }
    ht.put(JmxUtils.HOST, hht.get(JmxUtils.HOST));
    if (!ht.containsKey(JmxUtils.TYPE)) {
        ht.put(JmxUtils.TYPE, CRAWLJOB_JMXMBEAN_TYPE);
    }
    this.mbeanName = new ObjectName(on.getDomain(), ht);
    return this.mbeanName;
}

From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java

/**
 * {@inheritDoc}//from w ww. ja  v  a 2  s  .  c  o m
 * @see com.heliosapm.opentsdb.TSDBSubmitter#trace(javax.management.ObjectName, java.lang.String, java.util.Map, java.lang.String[])
 */
@Override
public void trace(final ObjectName target, final String metricName, final Map<String, Object> attributeValues,
        final String... objectNameKeys) {
    if (target == null)
        throw new IllegalArgumentException("The passed target ObjectName was null");
    if (objectNameKeys == null || objectNameKeys.length == 0)
        throw new IllegalArgumentException("At least one ObjectName Key is required");
    if (attributeValues == null || attributeValues.isEmpty())
        return;
    final String m = (metricName == null || metricName.trim().isEmpty()) ? target.getDomain()
            : metricName.trim();
    final Map<String, String> tags = new LinkedHashMap<String, String>(rootTagsMap);
    int keyCount = 0;
    boolean all = (objectNameKeys.length == 1 && "*".equals(objectNameKeys[0]));
    if (all) {
        for (Map.Entry<String, String> entry : target.getKeyPropertyList().entrySet()) {
            tags.put(clean(entry.getKey()), clean(entry.getValue()));
            keyCount++;
        }
    } else {
        for (String key : objectNameKeys) {
            if (key == null || key.trim().isEmpty())
                continue;
            String v = clean(target, key.trim());
            if (v == null || v.isEmpty())
                continue;
            tags.put(clean(key), clean(v));
            keyCount++;
        }
    }
    if (keyCount == 0)
        throw new IllegalArgumentException("No ObjectName Keys Usable as Tags. Keys: "
                + Arrays.toString(objectNameKeys) + ", ObjectName: [" + target.toString() + "]");

    for (Map.Entry<String, Object> attr : attributeValues.entrySet()) {
        final String attributeName = clean(attr.getKey());
        try {
            tags.put("metric", attributeName);
            final Object v = attr.getValue();
            if (v == null)
                continue;
            if (v instanceof Number) {
                if (v instanceof Double) {
                    trace(m, (Double) v, tags);
                } else {
                    trace(m, ((Number) v).longValue(), tags);
                }
            } else if (v instanceof CompositeData) {
                final CompositeData cd = (CompositeData) v;
                tags.put("ctype", attributeName);
                try {
                    Map<String, Number> cmap = fromOpenType(cd);
                    for (Map.Entry<String, Number> ce : cmap.entrySet()) {
                        final String key = clean(ce.getKey());
                        tags.put("metric", key);
                        try {
                            final Number cv = ce.getValue();
                            if (v instanceof Double) {
                                trace(m, cv.doubleValue(), tags);
                            } else {
                                trace(m, cv.longValue(), tags);
                            }
                        } finally {
                            tags.put("metric", attributeName);
                        }
                    }
                } finally {
                    tags.remove("ctype");
                }
            }
        } finally {
            tags.remove("metric");
        }
    }
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.metrics.MetricsReporter.java

/**
 * Collects JMX attributes of MBeans defined by <tt>objNameStr</tt>.
 *
 * @param objNameStr/*ww  w . j  a  v  a2 s  . c  o m*/
 *            MBeans object name pattern to query
 * @param mBeanServer
 *            MBean server instance to use
 * @param activity
 *            activity instance to put JMX metrics snapshots
 * @throws Exception
 *             if JMX attributes collecting fails
 */
public void collectMetricsJMX(String objNameStr, MBeanServer mBeanServer, Activity activity) throws Exception {
    ObjectName oName = new ObjectName(objNameStr);
    Set<ObjectName> metricsBeans = mBeanServer.queryNames(oName, null);

    for (ObjectName mBeanName : metricsBeans) {
        try {
            PropertySnapshot snapshot = new PropertySnapshot(mBeanName.getCanonicalName());
            MBeanInfo metricsBean = mBeanServer.getMBeanInfo(mBeanName);
            MBeanAttributeInfo[] pMetricsAttrs = metricsBean.getAttributes();
            for (MBeanAttributeInfo pMetricsAttr : pMetricsAttrs) {
                try {
                    String attrName = pMetricsAttr.getName();
                    Object attrValue = mBeanServer.getAttribute(mBeanName, attrName);
                    processAttrValue(snapshot, new PropertyNameBuilder(pMetricsAttr.getName()), attrValue);
                } catch (Exception exc) {
                    Utils.logThrowable(LOGGER, OpLevel.WARNING,
                            StreamsResources.getBundle(KafkaStreamConstants.RESOURCE_BUNDLE_NAME),
                            "MetricsReporter.bean.attr.fail", mBeanName, pMetricsAttr.getName(), exc);
                }
            }

            if (getSnapshotPropIgnoreCase(snapshot, OBJ_NAME_ENTRY_KEY) == null) {
                snapshot.add(OBJ_NAME_ENTRY_KEY, mBeanName.getCanonicalName());
            }
            if (useObjectNameProperties) {
                snapshot.add("domain", mBeanName.getDomain()); // NON-NLS
                Map<String, String> objNameProps = mBeanName.getKeyPropertyList();
                for (Map.Entry<String, String> objNameProp : objNameProps.entrySet()) {
                    String propKey = objNameProp.getKey();
                    Object mv = snapshot.get(propKey);
                    snapshot.add(propKey + (mv == null ? "" : "_"), objNameProp.getValue()); // NON-NLS
                }
            }
            activity.addSnapshot(snapshot);
        } catch (Exception exc) {
            Utils.logThrowable(LOGGER, OpLevel.WARNING,
                    StreamsResources.getBundle(KafkaStreamConstants.RESOURCE_BUNDLE_NAME),
                    "MetricsReporter.bean.info.fail", mBeanName, exc);
        }
    }
}

From source file:com.cyberway.issue.crawler.Heritrix.java

public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
    this.mbeanServer = server;
    @SuppressWarnings("unchecked")
    Hashtable<String, String> ht = name.getKeyPropertyList();
    if (!ht.containsKey(JmxUtils.NAME)) {
        throw new IllegalArgumentException("Name property required" + name.getCanonicalName());
    }/*from  w ww.  ja v  a 2s.c  om*/
    if (!ht.containsKey(JmxUtils.TYPE)) {
        ht.put(JmxUtils.TYPE, JmxUtils.SERVICE);
        name = new ObjectName(name.getDomain(), ht);
    }
    this.mbeanName = addGuiPort(addVitals(name));
    Heritrix.instances.put(this.mbeanName.getCanonicalKeyPropertyListString(), this);
    return this.mbeanName;
}