Example usage for java.lang.management ManagementFactory getPlatformMBeanServer

List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer

Introduction

In this page you can find the example usage for java.lang.management ManagementFactory getPlatformMBeanServer.

Prototype

public static synchronized MBeanServer getPlatformMBeanServer() 

Source Link

Document

Returns the platform javax.management.MBeanServer MBeanServer .

Usage

From source file:com.ricston.connectors.dataanalysis.DataAnalysisConnector.java

/**
 * Start the module by registering to the platform Mbean server, and starting the Map DB
 * /* w  w  w. ja  v  a  2 s  . c o m*/
 * @throws MalformedObjectNameException
 * @throws NotCompliantMBeanException
 * @throws InstanceAlreadyExistsException
 * @throws MBeanRegistrationException
 * @throws IOException 
 */
@Start
public void startModule() throws MalformedObjectNameException, NotCompliantMBeanException,
        InstanceAlreadyExistsException, MBeanRegistrationException, IOException {
    application = muleContext.getConfiguration().getId();

    logger.info("**********************************");
    logger.info("*Starting Data Analysis Connector*");
    logger.info("**********************************");

    startMapDb();

    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName id = new ObjectName(String.format(MBEAN_NAME, application));
    StandardMBean mbean = new StandardMBean(this, DataAnalysisMBean.class);
    server.registerMBean(mbean, id);

    logger.info("Registered mbean using name: " + String.format(MBEAN_NAME, application));
}

From source file:org.nuxeo.ecm.webapp.seam.NuxeoSeamFlusher.java

protected void invalidateWebSessions() throws IOException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name;/*from   ww  w .ja va2s .  c  o m*/
    try {
        name = new ObjectName("Catalina:type=Manager,context=/nuxeo,host=*");
    } catch (MalformedObjectNameException e) {
        throw new IOException(e);
    }
    for (ObjectInstance oi : mbs.queryMBeans(name, null)) {
        WebSessionFlusher flusher = JMX.newMBeanProxy(mbs, oi.getObjectName(), WebSessionFlusher.class);
        StringTokenizer tokenizer = new StringTokenizer(flusher.listSessionIds(), " ");
        while (tokenizer.hasMoreTokens()) {
            String id = tokenizer.nextToken();
            flusher.expireSession(id);
        }
    }
}

From source file:com.enioka.jqm.tools.Loader.java

Loader(JobInstance job, JqmEngine engine, QueuePoller p, ClassloaderManager clm) {
    this.p = p;/*from   w w w  .  ja  va  2  s  . c o m*/
    this.engine = engine;
    this.clm = clm;
    this.job = job;
    this.threadName = this.job.getJd().getApplicationName() + ";payload;" + this.job.getId();

    // JMX
    if (p != null && this.p.getEngine().loadJmxBeans) {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {
            name = new ObjectName(
                    "com.enioka.jqm:type=Node.Queue.JobInstance,Node=" + this.p.getEngine().getNode().getName()
                            + ",Queue=" + this.p.getQueue().getName() + ",name=" + this.job.getId());
            mbs.registerMBean(this, name);
        } catch (Exception e) {
            throw new JqmInitError("Could not create JMX bean for running job instance", e);
        }
    }
}

From source file:net.centro.rtb.monitoringcenter.metrics.tomcat.TomcatConnectorMetricSet.java

TomcatConnectorMetricSet(ObjectName threadPoolObjectName) {
    Preconditions.checkNotNull(threadPoolObjectName);

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    this.name = threadPoolObjectName.getKeyProperty("name");
    this.port = JmxUtil.getJmxAttribute(threadPoolObjectName, "port", Integer.class, null);

    Set<ObjectName> connectorObjectNames = null;
    try {/* w w  w  . j  a  va  2  s.c o m*/
        connectorObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,port=" + port),
                null);
    } catch (MalformedObjectNameException e) {
        logger.debug("Invalid ObjectName defined for the Tomcat's Connector MxBean for the {} thread pool",
                name, e);
    }

    if (connectorObjectNames != null && !connectorObjectNames.isEmpty()) {
        ObjectName connectorObjectName = connectorObjectNames.iterator().next();
        String internalPortStr = JmxUtil.getJmxAttribute(connectorObjectName, "internalPort", String.class,
                Boolean.FALSE.toString());
        this.isInternalPort = Boolean.TRUE.toString().equalsIgnoreCase(internalPortStr);
    }

    this.isSecure = JmxUtil.getJmxAttribute(threadPoolObjectName, "sSLEnabled", Boolean.class, Boolean.FALSE);
    this.isAjp = isAjpFromName(name);

    Map<String, Metric> metricsByNames = new HashMap<>();

    this.currentPoolSizeGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "currentThreadCount",
            Integer.class, 0);
    if (currentPoolSizeGauge != null) {
        metricsByNames.put("currentPoolSize", currentPoolSizeGauge);
    }

    this.maxPoolSizeGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "maxThreads", Integer.class,
            0);
    if (maxPoolSizeGauge != null) {
        metricsByNames.put("maxPoolSize", maxPoolSizeGauge);
    }

    this.busyThreadsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "currentThreadsBusy",
            Integer.class, 0);
    if (busyThreadsGauge != null) {
        metricsByNames.put("busyThreads", busyThreadsGauge);
    }

    this.activeConnectionsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "connectionCount",
            Long.class, 0L);
    if (activeConnectionsGauge != null) {
        metricsByNames.put("activeConnections", activeConnectionsGauge);
    }

    this.maxConnectionsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "maxConnections",
            Integer.class, 0);
    if (maxConnectionsGauge != null) {
        metricsByNames.put("maxConnections", maxConnectionsGauge);
    }

    Set<ObjectName> globalRequestProcessorObjectNames = null;
    try {
        globalRequestProcessorObjectNames = mBeanServer
                .queryNames(new ObjectName("Catalina:type=GlobalRequestProcessor,name=" + name), null);
    } catch (MalformedObjectNameException e) {
        logger.debug(
                "Invalid ObjectName defined for the Tomcat's GlobalRequestProcessor MxBean for the {} thread pool",
                name, e);
    }

    if (globalRequestProcessorObjectNames != null && !globalRequestProcessorObjectNames.isEmpty()) {
        ObjectName globalRequestProcessorObjectName = globalRequestProcessorObjectNames.iterator().next();
        this.totalRequestsGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName,
                "requestCount", Integer.class, 0);

        if (totalRequestsGauge != null) {
            metricsByNames.put("totalRequests", totalRequestsGauge);

            this.qpsHolder = new AtomicInteger();
            this.previousRequestCount = totalRequestsGauge.getValue();

            this.qpsGauge = new Gauge<Integer>() {
                @Override
                public Integer getValue() {
                    return qpsHolder.get();
                }
            };
            metricsByNames.put("qps", qpsGauge);
        }

        this.errorsGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName, "errorCount",
                Integer.class, 0);
        if (errorsGauge != null) {
            metricsByNames.put("errors", errorsGauge);
        }

        this.receivedBytesGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName,
                "bytesReceived", Long.class, 0L);
        if (receivedBytesGauge != null) {
            metricsByNames.put("receivedBytes", receivedBytesGauge);
        }

        this.sentBytesGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName, "bytesSent",
                Long.class, 0L);
        if (sentBytesGauge != null) {
            metricsByNames.put("sentBytes", sentBytesGauge);
        }
    }

    this.metricsByNames = metricsByNames;
}

From source file:org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar.java

@Override
public void afterPropertiesSet() throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    server.registerMBean(new SpringApplicationAdmin(), this.objectName);
    if (logger.isDebugEnabled()) {
        logger.debug("Application Admin MBean registered with name '" + this.objectName + "'");
    }/*w w  w  .j  a  va 2  s. c  om*/
}

From source file:de.micromata.mgc.springbootapp.JettyServletContainerCustomizer.java

protected void initJmx(Server server, JettyConfigModel config) {
    if (config.isServerEnableJmx() == false) {
        return;// w  w w. j  ava  2 s  . c  o m
    }
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    for (Handler h : server.getHandlers()) {
        addEventListener(h, mBeanContainer);
    }
}

From source file:com.todo.backend.config.MetricsConfiguration.java

@PostConstruct
public void init() {

    log.debug("Registering JVM gauges");

    metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet());
    metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet());
    metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet());
    metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge());
    metricRegistry.register(PROP_METRIC_REG_JVM_BUFFERS,
            new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));

    if (customProperties.getMetrics().getLogs().isEnabled()) {

        log.info("Initializing Metrics Log reporting...");

        final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry)
                .outputTo(LoggerFactory.getLogger(METRICS)).convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS).build();
        reporter.start(1, TimeUnit.HOURS);
    }// www  .  jav  a  2 s .  co m

    if (customProperties.getMetrics().getGraphite().isEnabled()) {

        log.info("Initializing Metrics Graphite reporting...");

        final String host = customProperties.getMetrics().getGraphite().getHost();
        final Integer port = customProperties.getMetrics().getGraphite().getPort();
        final String prefix = customProperties.getMetrics().getGraphite().getPrefix();
        final Graphite graphite = new Graphite(new InetSocketAddress(host, port));
        final GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).prefixedWith(prefix)
                .build(graphite);
        graphiteReporter.start(1, TimeUnit.HOURS);
    }
}

From source file:org.wso2.carbon.andes.cluster.mgt.internal.managementBeans.ClusterManagementBeans.java

/**
 * Gets the current node's ID// w  ww.jav  a 2 s  .  c o m
 *
 * @return current node's ID
 * @throws ClusterMgtException
 */
public String getMyNodeID() throws ClusterMgtException {
    String myNodeID = "";
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName objectName = new ObjectName(
                "org.wso2.andes:type=ClusterManagementInformation," + "name=ClusterManagementInformation");
        Object result = mBeanServer.getAttribute(objectName, ClusterMgtConstants.MY_NODE_ID);

        if (result != null) {
            myNodeID = (String) result;
        }
        return myNodeID;

    } catch (MalformedObjectNameException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (InstanceNotFoundException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (ReflectionException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (AttributeNotFoundException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (MBeanException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    }
}

From source file:com.hellblazer.slp.jmx.JmxDiscoveryConfiguration.java

public JmxServerListener construct() throws Exception {
    ServiceScope scope = discovery.construct();
    scope.start();/*from   w w  w.j ava  2 s. c  o  m*/
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    CascadingService cascadingService = new CascadingService();
    mbs.registerMBean(cascadingService, new ObjectName(name));
    JmxServerListener listener = new JmxServerListener(cascadingService, sourcePattern, sourceMap, scope,
            targetPath);
    for (String serviceType : serviceNames) {
        listener.listenFor("(" + SERVICE_TYPE + "=" + serviceType + ")");
    }
    return listener;
}

From source file:gridool.metrics.GridNodeMetricsProvider.java

private static void registerMBeans(GridLocalNodeMetrics metrics) {
    final StandardMBean mbean;
    try {/*from   w  w  w . ja  v  a 2 s  .c o  m*/
        mbean = new StandardMBean(metrics, GridNodeMetricsMBean.class);
    } catch (NotCompliantMBeanException e) {
        LOG.error("Unexpected as GridNodeMetricsMBean: " + metrics.getClass().getName(), e);
        return;
    }
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final ObjectName name = GridUtils.makeMBeanName("gridool", "GridService", "GridLocalNodeMetrics");
    try {
        server.registerMBean(mbean, name);
    } catch (Exception e) {
        LOG.error("Failed registering mbean: " + name, e);
    }
}