Example usage for javax.management.j2ee.statistics Stats getStatistic

List of usage examples for javax.management.j2ee.statistics Stats getStatistic

Introduction

In this page you can find the example usage for javax.management.j2ee.statistics Stats getStatistic.

Prototype

Statistic getStatistic(String statisticName);

Source Link

Document

Get a Statistic by name.

Usage

From source file:org.hyperic.hq.plugin.jboss.JBossUtil.java

static Double getJSR77Statistic(MBeanServerConnection mServer, ObjectName objName, Metric metric, boolean lc)
        throws MetricNotFoundException, MetricInvalidException, MetricUnreachableException, PluginException {

    //jboss changed attribute case in version 4.0
    String[] attrs;// w  w w . j a v  a 2s .  co  m
    if (lc) {
        attrs = STAT_PROVIDER_4;
    } else {
        attrs = STAT_PROVIDER;
    }

    Stats stats;
    try {
        Boolean provider = (Boolean) mServer.getAttribute(objName, attrs[0]);
        if ((provider == null) || !provider.booleanValue()) {
            String msg = "MBeanServerConnection does not provide statistics";
            throw new PluginException(msg);
        }

        stats = (Stats) mServer.getAttribute(objName, attrs[1]);
    } catch (RemoteException e) {
        throw unreachable(metric, e);
    } catch (InstanceNotFoundException e) {
        throw notfound(metric, e);
    } catch (AttributeNotFoundException e) {
        throw notfound(metric, e);
    } catch (ReflectionException e) {
        throw error(metric, e);
    } catch (MBeanException e) {
        throw error(metric, e);
    } catch (IOException e) {
        throw error(metric, e);
    }

    if (stats == null) {
        throw new PluginException("MBeanServerConnection has no stats");
    }

    String statName = metric.getAttributeName().substring(9);
    Statistic stat = stats.getStatistic(statName);
    if (stat == null) {
        String msg = "Statistic '" + statName + "' not found [" + metric + "]";
        throw new MetricNotFoundException(msg);
    }

    long value;
    if (stat instanceof CountStatistic) {
        value = ((CountStatistic) stat).getCount();
    } else if (stat instanceof RangeStatistic) {
        value = ((RangeStatistic) stat).getCurrent();
    } else {
        String msg = "Unsupported statistic type [" + statName.getClass().getName() + " for [" + metric + "]";
        throw new MetricInvalidException(msg);
    }

    return new Double(value);
}

From source file:org.hyperic.hq.plugin.websphere.WebsphereCollector.java

protected final double getStatCount(Stats stats, String metric) {
    Statistic stat = stats.getStatistic(metric);
    if (stat == null) {
        return MetricValue.VALUE_NONE;
    }//  www.  j a  v a2  s. c  om
    return getStatCount(stat);
}

From source file:org.hyperic.hq.product.jmx.MxUtil.java

static Double getJSR77Statistic(MBeanServerConnection mServer, ObjectName objName, String attribute)
        throws MalformedURLException, MalformedObjectNameException, IOException, MBeanException,
        AttributeNotFoundException, InstanceNotFoundException, ReflectionException, PluginException {

    Stats stats;
    Boolean provider = (Boolean) mServer.getAttribute(objName, "statisticsProvider");
    if ((provider == null) || !provider.booleanValue()) {
        String msg = objName + " does not provide statistics";
        throw new PluginException(msg);
    }/*from  w ww . j a  v a  2s.c om*/

    stats = (Stats) mServer.getAttribute(objName, "stats");

    if (stats == null) {
        throw new PluginException(objName + " has no stats");
    }

    String statName = attribute.substring(STATS_PREFIX.length());
    Statistic stat = stats.getStatistic(statName);
    if (stat == null) {
        String msg = "Statistic '" + statName + "' not found [" + objName + "]";
        throw new AttributeNotFoundException(msg);
    }

    long value;
    if (stat instanceof CountStatistic) {
        value = ((CountStatistic) stat).getCount();
    } else if (stat instanceof RangeStatistic) {
        value = ((RangeStatistic) stat).getCurrent();
    } else if (stat instanceof TimeStatistic) {
        // get the average time
        long count = ((TimeStatistic) stat).getCount();
        if (count == 0)
            value = 0;
        else
            value = ((TimeStatistic) stat).getTotalTime() / count;
    } else {
        String msg = "Unsupported statistic type [" + statName.getClass().getName() + " for [" + objName + ":"
                + attribute + "]";
        throw new MetricInvalidException(msg);
    }

    //XXX: handle bug with geronimo uptime metric
    if (statName.equals("UpTime")) {
        value = System.currentTimeMillis() - value;
    }

    return new Double(value);
}