当前位置: 首页>>代码示例>>Java>>正文


Java MBeanServer.queryMBeans方法代码示例

本文整理汇总了Java中javax.management.MBeanServer.queryMBeans方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServer.queryMBeans方法的具体用法?Java MBeanServer.queryMBeans怎么用?Java MBeanServer.queryMBeans使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.MBeanServer的用法示例。


在下文中一共展示了MBeanServer.queryMBeans方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: collect

import javax.management.MBeanServer; //导入方法依赖的package包/类
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<>();
    try {
        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        final ObjectName filterName = new ObjectName("jboss.as:management-root=server");
        Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
        if (mBeans.size() > 0 ) {

            GaugeMetricFamily wildflyInfo = new GaugeMetricFamily(
                    "wildfly_info",
                    "Wildfly version info",
                    Arrays.asList("name", "version"));

            for (final ObjectInstance mBean : mBeans) {
                wildflyInfo.addMetric(Arrays.asList((String) server.getAttribute(mBean.getObjectName(), "productName"), (String) server.getAttribute(mBean.getObjectName(), "productVersion")), 1);
            }
            mfs.add(wildflyInfo);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mfs;
}
 
开发者ID:nlighten,项目名称:wildfly_exporter,代码行数:24,代码来源:WildflyVersionExports.java

示例2: testJmxBeans

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void testJmxBeans() throws Exception {
  final int NUM_SERVERS = 3;
  final MiniRaftClusterWithSimulatedRpc cluster
      = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster(3, new RaftProperties());
  cluster.start();
  waitForLeader(cluster);

  MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
  Set<ObjectInstance> objectInstances = platformMBeanServer.queryMBeans(new ObjectName("Ratis:*"), null);
  Assert.assertEquals(NUM_SERVERS, objectInstances.size());

  for (ObjectInstance instance : objectInstances) {
    Object groupId = platformMBeanServer.getAttribute(instance.getObjectName(), "GroupId");
    Assert.assertEquals(cluster.getGroupId().toString(), groupId);
  }
  cluster.shutdown();
}
 
开发者ID:apache,项目名称:incubator-ratis,代码行数:19,代码来源:TestRaftServerJmx.java

示例3: getListenPort

import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
   * Retrieves HTTP listen port used by the app. It assumes there
   * is only one HTTP connector.
   */
  private int getListenPort() {
    int port = 8080;
    try {
      // get connectors
      final MBeanServer mbeanServer = (MBeanServer) getServletContext().getAttribute("org.apache.catalina.MBeanServer");
//      if (log.isDebugEnabled()) log.debug("server: " + mbeanServer);
      final ObjectName objectName = new ObjectName("Catalina:type=Connector,*");
      final Set mbeans = mbeanServer.queryMBeans(objectName, null);
      // find http connector
      for (final Iterator i = mbeans.iterator(); i.hasNext();) {
        final ObjectInstance mbean = (ObjectInstance) i.next();
//        if (log.isDebugEnabled()) log.debug("mbean: " + mbean);
//        if (log.isDebugEnabled()) log.debug("mbean.getClassName(): " + mbean.getClassName());
//        if (log.isDebugEnabled()) log.debug("mbean.getObjectName(): " + mbean.getObjectName());
//        if (log.isDebugEnabled()) log.debug("connector className: " + mbeanServer.getAttribute(mbean.getObjectName(), "className"));
        final String handlerClassName = (String) mbeanServer.getAttribute(mbean.getObjectName(), "className");
        // is it HTTP connector?
        if (handlerClassName.endsWith("HttpConnector")) {
          port = ((Integer) mbeanServer.getAttribute(mbean.getObjectName(), "port")).intValue();
          if (log.isDebugEnabled()) {
            log.debug("port: " + port);
          }
          break;
        }
      }
    } catch (Exception e) {
      // just log error, default value will be used
      log.error("Error while getting connector list", e);
    }
    return port;
  }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:36,代码来源:ServiceManagerServlet.java

示例4: isTomcatJdbcUsed

import javax.management.MBeanServer; //导入方法依赖的package包/类
public static boolean isTomcatJdbcUsed() {
    try {
        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName filterName = new ObjectName("tomcat.jdbc:class=org.apache.tomcat.jdbc.pool.DataSource,type=ConnectionPool,*");
        Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
        return !mBeans.isEmpty();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:nlighten,项目名称:tomcat_exporter,代码行数:12,代码来源:TomcatJdbcPoolExports.java

示例5: ConfigRegistryJMXClient

import javax.management.MBeanServer; //导入方法依赖的package包/类
private ConfigRegistryJMXClient(final MBeanServer configMBeanServer, final ObjectName configRegistryON) {
    this.configMBeanServer = configMBeanServer;
    this.configRegistryON = configRegistryON;
    Set<ObjectInstance> searchResult = configMBeanServer.queryMBeans(configRegistryON, null);
    if (searchResult.size() != 1) {
        throw new IllegalStateException("Config registry not found");
    }
    configRegistryMXBeanProxy = JMX.newMXBeanProxy(configMBeanServer, configRegistryON, ConfigRegistryMXBean.class,
            false);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:11,代码来源:ConfigRegistryJMXClient.java

示例6: collect

import javax.management.MBeanServer; //导入方法依赖的package包/类
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<>();
    try {
        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        final ObjectName filterName = new ObjectName("jboss.infinispan:component=Statistics,name=*,manager=*,type=Cache");
        Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
        if (mBeans.size() > 0) {

            GaugeMetricFamily hitRatioGauge = new GaugeMetricFamily(
                    "infinispan_hit_ratio",
                    "Cache hit ratio",
                    Arrays.asList("name", "manager"));

            CounterMetricFamily hitsCounter = new CounterMetricFamily(
                    "infinispan_hit_total",
                    "Number of hits",
                    Arrays.asList("name", "manager"));

            CounterMetricFamily missesCounter = new CounterMetricFamily(
                    "infinispan_miss_total",
                    "Number of misses",
                    Arrays.asList("name", "manager"));

            GaugeMetricFamily numberOfEntriesGauge = new GaugeMetricFamily(
                    "infinispan_entries_total",
                    "Number of entries",
                    Arrays.asList("name", "manager"));

            CounterMetricFamily evictionsCounter = new CounterMetricFamily(
                    "infinispan_evictions_total",
                    "Number of evictions",
                    Arrays.asList("name", "manager"));

            for (final ObjectInstance mBean : mBeans) {

                hitRatioGauge.addMetric(
                        Arrays.asList(Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("name")), Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("manager"))),
                        (Double) server.getAttribute(mBean.getObjectName(), "hitRatio"));
                hitsCounter.addMetric(
                        Arrays.asList(Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("name")), Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("manager"))),
                        ((Long) server.getAttribute(mBean.getObjectName(), "hits")).doubleValue());

                missesCounter.addMetric(
                        Arrays.asList(Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("name")), Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("manager"))),
                        ((Long) server.getAttribute(mBean.getObjectName(), "misses")).doubleValue());

                numberOfEntriesGauge.addMetric(
                        Arrays.asList(Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("name")), Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("manager"))),
                        ((Integer) server.getAttribute(mBean.getObjectName(), "numberOfEntries")).doubleValue());

                evictionsCounter.addMetric(
                        Arrays.asList(Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("name")), Util.sanitizeLabel(mBean.getObjectName().getKeyProperty("manager"))),
                        ((Long) server.getAttribute(mBean.getObjectName(), "evictions")).doubleValue());

            }
            mfs.add(hitRatioGauge);
            mfs.add(hitsCounter);
            mfs.add(missesCounter);
            mfs.add(numberOfEntriesGauge);
            mfs.add(evictionsCounter);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mfs;
}
 
开发者ID:nlighten,项目名称:wildfly_exporter,代码行数:68,代码来源:InfinispanExports.java

示例7: collect

import javax.management.MBeanServer; //导入方法依赖的package包/类
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
    try {
        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName filterName = new ObjectName("tomcat.jdbc:class=org.apache.tomcat.jdbc.pool.DataSource,type=ConnectionPool,*");
        Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);

        if (mBeans.size() > 0) {
            List<String> labelList = Collections.singletonList("pool");

            GaugeMetricFamily maxActiveConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_max",
                    "Maximum number of active connections that can be allocated from this pool at the same time",
                    labelList);

            GaugeMetricFamily activeConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_active_total",
                    "Number of active connections allocated from this pool",
                    labelList);

            GaugeMetricFamily idleConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_idle_total",
                    "Number of idle connections in this pool",
                    labelList);

            GaugeMetricFamily totalConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_total",
                    "Total number of connections in this pool",
                    labelList);

            GaugeMetricFamily waitingThreadsCountGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_waitingthreads_total",
                    "Number of threads waiting for connections from this pool",
                    labelList);

            for (final ObjectInstance mBean : mBeans) {
                List<String> labelValueList = Collections.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));

                maxActiveConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "MaxActive")).doubleValue());

                activeConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "Active")).doubleValue());

                idleConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "Idle")).doubleValue());

                totalConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "Size")).doubleValue());

                waitingThreadsCountGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "WaitCount")).doubleValue());
            }

            mfs.add(maxActiveConnectionsGauge);
            mfs.add(activeConnectionsGauge);
            mfs.add(idleConnectionsGauge);
            mfs.add(totalConnectionsGauge);
            mfs.add(waitingThreadsCountGauge);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mfs;
}
 
开发者ID:nlighten,项目名称:tomcat_exporter,代码行数:71,代码来源:TomcatJdbcPoolExports.java

示例8: addRequestProcessorMetrics

import javax.management.MBeanServer; //导入方法依赖的package包/类
private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
    try {
        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
        Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);

        if (mBeans.size() > 0) {
            List<String> labelNameList = Collections.singletonList("name");

            GaugeMetricFamily requestProcessorBytesReceivedGauge = new GaugeMetricFamily(
                    "tomcat_requestprocessor_received_bytes",
                    "Number of bytes received by this request processor",
                    labelNameList);

            GaugeMetricFamily requestProcessorBytesSentGauge = new GaugeMetricFamily(
                    "tomcat_requestprocessor_sent_bytes",
                    "Number of bytes sent by this request processor",
                    labelNameList);

            GaugeMetricFamily requestProcessorProcessingTimeGauge = new GaugeMetricFamily(
                    "tomcat_requestprocessor_time_seconds",
                    "The total time spend by this request processor",
                    labelNameList);

            CounterMetricFamily requestProcessorErrorCounter = new CounterMetricFamily(
                    "tomcat_requestprocessor_error_count",
                    "The number of error request served by this request processor",
                    labelNameList);

            CounterMetricFamily requestProcessorRequestCounter = new CounterMetricFamily(
                    "tomcat_requestprocessor_request_count",
                    "The number of request served by this request processor",
                    labelNameList);

            for (final ObjectInstance mBean : mBeans) {
                List<String> labelValueList = Collections.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));

                requestProcessorBytesReceivedGauge.addMetric(
                        labelValueList,
                        ((Long) server.getAttribute(mBean.getObjectName(), "bytesReceived")).doubleValue());

                requestProcessorBytesSentGauge.addMetric(
                        labelValueList,
                        ((Long) server.getAttribute(mBean.getObjectName(), "bytesSent")).doubleValue());

                requestProcessorProcessingTimeGauge.addMetric(
                        labelValueList,
                        ((Long) server.getAttribute(mBean.getObjectName(), "processingTime")).doubleValue() / 1000.0);

                requestProcessorErrorCounter.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "errorCount")).doubleValue());

                requestProcessorRequestCounter.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "requestCount")).doubleValue());
            }

            mfs.add(requestProcessorBytesReceivedGauge);
            mfs.add(requestProcessorBytesSentGauge);
            mfs.add(requestProcessorProcessingTimeGauge);
            mfs.add(requestProcessorRequestCounter);
            mfs.add(requestProcessorErrorCounter);
        }
    } catch (Exception e) {
        log.error("Error retrieving metric.", e);
    }
}
 
开发者ID:nlighten,项目名称:tomcat_exporter,代码行数:69,代码来源:TomcatGenericExports.java

示例9: addThreadPoolMetrics

import javax.management.MBeanServer; //导入方法依赖的package包/类
private void addThreadPoolMetrics(List<MetricFamilySamples> mfs) {
    try {
        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName filterName = new ObjectName(jmxDomain + ":type=ThreadPool,name=*");
        Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);

        if (mBeans.size() > 0) {
            List<String> labelList = Collections.singletonList("name");

            GaugeMetricFamily threadPoolCurrentCountGauge = new GaugeMetricFamily(
                    "tomcat_threads_total",
                    "Number threads in this pool.",
                    labelList);

            GaugeMetricFamily threadPoolActiveCountGauge = new GaugeMetricFamily(
                    "tomcat_threads_active_total",
                    "Number of active threads in this pool.",
                    labelList);

            GaugeMetricFamily threadPoolMaxThreadsGauge = new GaugeMetricFamily(
                    "tomcat_threads_max",
                    "Maximum number of threads allowed in this pool.",
                    labelList);

            GaugeMetricFamily threadPoolConnectionCountGauge = new GaugeMetricFamily(
                    "tomcat_connections_active_total",
                    "Number of connections served by this pool.",
                    labelList);

            GaugeMetricFamily threadPoolMaxConnectionGauge = new GaugeMetricFamily(
                        "tomcat_connections_active_max",
                    "Maximum number of concurrent connections served by this pool.",
                    labelList);

            for (final ObjectInstance mBean : mBeans) {
                List<String> labelValueList = Collections.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));

                threadPoolCurrentCountGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "currentThreadCount")).doubleValue());

                threadPoolActiveCountGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "currentThreadsBusy")).doubleValue());

                threadPoolMaxThreadsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "maxThreads")).doubleValue());

                threadPoolConnectionCountGauge.addMetric(
                        labelValueList,
                        ((Long) server.getAttribute(mBean.getObjectName(), "connectionCount")).doubleValue());

                threadPoolMaxConnectionGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "maxConnections")).doubleValue());

            }

            mfs.add(threadPoolCurrentCountGauge);
            mfs.add(threadPoolActiveCountGauge);
            mfs.add(threadPoolMaxThreadsGauge);
            mfs.add(threadPoolConnectionCountGauge);
            mfs.add(threadPoolMaxConnectionGauge);
        }
    } catch (Exception e) {
        log.error("Error retrieving metric.", e);
    }
}
 
开发者ID:nlighten,项目名称:tomcat_exporter,代码行数:70,代码来源:TomcatGenericExports.java


注:本文中的javax.management.MBeanServer.queryMBeans方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。