List of usage examples for javax.management ObjectName ObjectName
public ObjectName(String name) throws MalformedObjectNameException
From source file:com.taobao.diamond.server.service.jmx.DataIdCountService.java
public void init() { try {/*from w ww . ja va 2 s . co m*/ ObjectName oName = new ObjectName(DataIdCountService.class.getPackage().getName() + ":type=" + DataIdCountService.class.getSimpleName()); ManagementFactory.getPlatformMBeanServer().registerMBean(this, oName); } catch (Exception e) { log.error("DataIdCountServicembean", e); } }
From source file:be.eliwan.profiling.jmx.BindJmxTest.java
@Test public void testJmx() throws Exception { ObjectName mbean = new ObjectName("bean:name=profilingTest"); mBeanServer.invoke(mbean, "clear", new Object[] {}, new String[] {}); service.doSomething(1);//ww w . j a va2 s . c o m service.doSomething(2); service.doSomething(3); System.out.println("" + mBeanServer.getAttribute(mbean, "Total")); Assert.assertEquals(3, ((OneContainer) mBeanServer.getAttribute(mbean, "Total")).getInvocationCount()); System.out.println("" + mBeanServer.getAttribute(mbean, "GroupData")); //Thread.sleep(1000000000); // use this to test whether you can connect using JConsole }
From source file:be.eliwan.profiling.jmx.BindAopTest.java
@Test public void testAopJmx() throws Exception { ObjectName mbean = new ObjectName("bean:name=profilingAopTest"); mBeanServer.invoke(mbean, "clear", new Object[] {}, new String[] {}); service.doSomething(1);//w ww . j av a2 s .c o m service.doSomething(2); service.doSomething(3); System.out.println("" + mBeanServer.getAttribute(mbean, "Total")); Assert.assertEquals(3, ((OneContainer) mBeanServer.getAttribute(mbean, "Total")).getInvocationCount()); System.out.println("" + mBeanServer.getAttribute(mbean, "GroupData")); //Thread.sleep(1000000000); // use this to test whether you can connect using JConsole }
From source file:com.googlecode.psiprobe.beans.RuntimeInfoAccessorBean.java
public RuntimeInformation getRuntimeInformation() throws Exception { MBeanServer mBeanServer = new Registry().getMBeanServer(); RuntimeInformation ri = new RuntimeInformation(); try {/*from w w w . ja va 2 s .c om*/ ObjectName runtimeOName = new ObjectName("java.lang:type=Runtime"); ri.setStartTime(JmxTools.getLongAttr(mBeanServer, runtimeOName, "StartTime")); ri.setUptime(JmxTools.getLongAttr(mBeanServer, runtimeOName, "Uptime")); ri.setVmVendor(JmxTools.getStringAttr(mBeanServer, runtimeOName, "VmVendor")); ObjectName osOName = new ObjectName("java.lang:type=OperatingSystem"); ri.setOsName(JmxTools.getStringAttr(mBeanServer, osOName, "Name")); ri.setOsVersion(JmxTools.getStringAttr(mBeanServer, osOName, "Version")); if (!ri.getVmVendor().startsWith("IBM Corporation")) { ri.setTotalPhysicalMemorySize( JmxTools.getLongAttr(mBeanServer, osOName, "TotalPhysicalMemorySize")); ri.setCommittedVirtualMemorySize( JmxTools.getLongAttr(mBeanServer, osOName, "CommittedVirtualMemorySize")); ri.setFreePhysicalMemorySize(JmxTools.getLongAttr(mBeanServer, osOName, "FreePhysicalMemorySize")); ri.setFreeSwapSpaceSize(JmxTools.getLongAttr(mBeanServer, osOName, "FreeSwapSpaceSize")); ri.setTotalSwapSpaceSize(JmxTools.getLongAttr(mBeanServer, osOName, "TotalSwapSpaceSize")); ri.setProcessCpuTime(JmxTools.getLongAttr(mBeanServer, osOName, "ProcessCpuTime")); ri.setAvailableProcessors(Runtime.getRuntime().availableProcessors()); } else { ri.setTotalPhysicalMemorySize(JmxTools.getLongAttr(mBeanServer, osOName, "TotalPhysicalMemory")); } if (JmxTools.hasAttribute(mBeanServer, osOName, "OpenFileDescriptorCount") && JmxTools.hasAttribute(mBeanServer, osOName, "MaxFileDescriptorCount")) { ri.setOpenFDCount(JmxTools.getLongAttr(mBeanServer, osOName, "OpenFileDescriptorCount")); ri.setMaxFDCount(JmxTools.getLongAttr(mBeanServer, osOName, "MaxFileDescriptorCount")); } return ri; } catch (Exception e) { logger.debug("OS information is unavailable"); return null; } }
From source file:com.amazonaws.client.metrics.support.JmxInfoProviderSupport.java
@Override public long[] getFileDecriptorInfo() { MBeanServer mbsc = MBeans.getMBeanServer(); AttributeList attributes;/*from ww w .j a va2 s . co m*/ try { attributes = mbsc.getAttributes(new ObjectName("java.lang:type=OperatingSystem"), new String[] { "OpenFileDescriptorCount", "MaxFileDescriptorCount" }); List<Attribute> attrList = attributes.asList(); long openFdCount = (Long) attrList.get(0).getValue(); long maxFdCount = (Long) attrList.get(1).getValue(); long[] fdCounts = { openFdCount, maxFdCount }; return fdCounts; } catch (Exception e) { LogFactory.getLog(SdkMBeanRegistrySupport.class).debug("Failed to retrieve file descriptor info", e); } return null; }
From source file:com.meltmedia.cadmium.deployer.JBossUtil.java
public static boolean isWarDeployed(String warName, Logger log) throws Exception { MBeanServer server = MBeanServerLocator.locateJBoss(); Set<ObjectInstance> foundInstances = server .queryMBeans(new ObjectName("jboss.deployment:type=Deployment,id=\"*" + warName + "*\""), null); boolean found = false; if (foundInstances != null && foundInstances.size() > 0) { log.debug("MBean query returned: {} results.", foundInstances.size()); for (ObjectInstance instance : foundInstances) { String simpleName = "" + server.getAttribute(instance.getObjectName(), "SimpleName"); log.debug("Checking {} is {}", simpleName, warName); if (simpleName.equals(warName)) { found = true;/*w w w . j ava 2s. c o m*/ String state = server.getAttribute(instance.getObjectName(), "State") + ""; log.debug("Deployment state {}", state); if (state.equals("ERROR")) { Object error = server.getAttribute(instance.getObjectName(), "Problem"); log.debug("Found problem: {}", error); if (error instanceof Throwable) { throw new Exception((Throwable) error); } else { throw new Exception(error.toString()); } } else if (state.equals("DEPLOYED")) { return true; } else if (state.equals("UNDEPLOYED")) { found = false; } } } } if (!found) { throw new NoDeploymentFoundException(); } return false; }
From source file:com.custardsource.maven.plugins.jmx.SetAttribute.java
@Override public Object execute(MBeanServerConnection connection) throws Exception { ObjectName name = new ObjectName(objectName); ConvertUtilsBean converter = new ConvertUtilsBean(); Object attributeValue = converter.convert(value, ClassUtils.getClass(type)); connection.setAttribute(name, new Attribute(attributeName, attributeValue)); return connection.getAttribute(name, attributeName); }
From source file:com.googlecode.psiprobe.beans.JvmMemoryInfoAccessorBean.java
public List getPools() throws Exception { List memoryPools = new LinkedList(); MBeanServer mBeanServer = new Registry().getMBeanServer(); Set memoryOPools = mBeanServer.queryMBeans(new ObjectName("java.lang:type=MemoryPool,*"), null); ///* ww w . j av a 2s . com*/ // totals // long totalInit = 0; long totalMax = 0; long totalUsed = 0; long totalCommitted = 0; for (Iterator it = memoryOPools.iterator(); it.hasNext();) { ObjectInstance oi = (ObjectInstance) it.next(); ObjectName oName = oi.getObjectName(); MemoryPool memoryPool = new MemoryPool(); memoryPool.setName(JmxTools.getStringAttr(mBeanServer, oName, "Name")); memoryPool.setType(JmxTools.getStringAttr(mBeanServer, oName, "Type")); CompositeDataSupport cd = (CompositeDataSupport) mBeanServer.getAttribute(oName, "Usage"); // // It seems that "Usage" attribute of one of the pools may turn into null intermittently. We better have a // dip in the graph then an NPE though. // if (cd != null) { memoryPool.setMax(JmxTools.getLongAttr(cd, "max")); memoryPool.setUsed(JmxTools.getLongAttr(cd, "used")); memoryPool.setInit(JmxTools.getLongAttr(cd, "init")); memoryPool.setCommitted(JmxTools.getLongAttr(cd, "committed")); } else { logger.error("Oops, JVM problem? " + oName.toString() + " \"Usage\" attribute is NULL!"); } totalInit += memoryPool.getInit(); totalMax += memoryPool.getMax(); totalUsed += memoryPool.getUsed(); totalCommitted += memoryPool.getCommitted(); memoryPools.add(memoryPool); } if (!memoryPools.isEmpty()) { MemoryPool pool = new MemoryPool(); pool.setName("Total"); pool.setType("TOTAL"); pool.setInit(totalInit); pool.setUsed(totalUsed); pool.setMax(totalMax); pool.setCommitted(totalCommitted); memoryPools.add(pool); } return memoryPools; }
From source file:com.clustercontrol.plugin.impl.SummaryPlugin.java
@Override public void activate() { try {//from www . ja va2 s. c o m ManagementFactory.getPlatformMBeanServer().registerMBean(new Manager(), new ObjectName("com.clustercontrol.mbean:type=" + ManagerMXBean.class.getSimpleName())); } catch (Exception e) { log.error(e); } }
From source file:com.googlecode.psiprobe.beans.ClusterWrapperBean.java
public Cluster getCluster(String serverName, String hostName, boolean loadMembers) throws Exception { Cluster cluster = null;/*from www. ja v a 2s . c o m*/ MBeanServer mBeanServer = new Registry().getMBeanServer(); ObjectName membershipOName = new ObjectName(serverName + ":type=ClusterMembership,host=" + hostName); ObjectName receiverOName = new ObjectName(serverName + ":type=ClusterReceiver,host=" + hostName); ObjectName senderOName = new ObjectName(serverName + ":type=ClusterSender,host=" + hostName); // // should be just one set, this is just to find out if this instance // is cluster-enabled and the cluster supports JMX // Set clusters = mBeanServer.queryMBeans(new ObjectName("*:type=Cluster,host=" + hostName), null); Set membership = mBeanServer.queryMBeans(membershipOName, null); if (clusters != null && clusters.size() > 0 && membership != null && membership.size() > 0) { ObjectName clusterOName = ((ObjectInstance) clusters.iterator().next()).getObjectName(); cluster = new Cluster(); cluster.setName(JmxTools.getStringAttr(mBeanServer, clusterOName, "clusterName")); cluster.setInfo(JmxTools.getStringAttr(mBeanServer, clusterOName, "info")); cluster.setManagerClassName(JmxTools.getStringAttr(mBeanServer, clusterOName, "managerClassName")); cluster.setMcastAddress(JmxTools.getStringAttr(mBeanServer, membershipOName, "mcastAddr")); cluster.setMcastBindAddress(JmxTools.getStringAttr(mBeanServer, membershipOName, "mcastBindAddress")); cluster.setMcastClusterDomain( JmxTools.getStringAttr(mBeanServer, membershipOName, "mcastClusterDomain")); cluster.setMcastDropTime(JmxTools.getLongAttr(mBeanServer, membershipOName, "mcastDropTime")); cluster.setMcastFrequency(JmxTools.getLongAttr(mBeanServer, membershipOName, "mcastFrequency")); cluster.setMcastPort(JmxTools.getIntAttr(mBeanServer, membershipOName, "mcastPort")); cluster.setMcastSoTimeout(JmxTools.getIntAttr(mBeanServer, membershipOName, "mcastSoTimeout")); cluster.setMcastTTL(JmxTools.getIntAttr(mBeanServer, membershipOName, "mcastTTL")); cluster.setTcpListenAddress(JmxTools.getStringAttr(mBeanServer, receiverOName, "tcpListenAddress")); cluster.setTcpListenPort(JmxTools.getIntAttr(mBeanServer, receiverOName, "tcpListenPort")); cluster.setNrOfMsgsReceived(JmxTools.getLongAttr(mBeanServer, receiverOName, "nrOfMsgsReceived")); cluster.setTotalReceivedBytes(JmxTools.getLongAttr(mBeanServer, receiverOName, "totalReceivedBytes")); // cluster.setTcpSelectorTimeout(getLongAttr(mBeanServer, receiverOName, "tcpSelectorTimeout")); // cluster.setTcpThreadCount(getIntAttr(mBeanServer, receiverOName, "tcpThreadCount")); cluster.setSenderAckTimeout(JmxTools.getLongAttr(mBeanServer, senderOName, "ackTimeout")); cluster.setSenderAutoConnect( ((Boolean) mBeanServer.getAttribute(senderOName, "autoConnect")).booleanValue()); cluster.setSenderFailureCounter(JmxTools.getLongAttr(mBeanServer, senderOName, "failureCounter")); cluster.setSenderNrOfRequests(JmxTools.getLongAttr(mBeanServer, senderOName, "nrOfRequests")); cluster.setSenderReplicationMode(JmxTools.getStringAttr(mBeanServer, senderOName, "replicationMode")); cluster.setSenderTotalBytes(JmxTools.getLongAttr(mBeanServer, senderOName, "totalBytes")); if (loadMembers) { ObjectName senders[] = (ObjectName[]) mBeanServer.getAttribute(senderOName, "senderObjectNames"); for (int i = 0; i < senders.length; i++) { ClusterSender sender; if ("pooled".equals(cluster.getSenderReplicationMode())) { sender = new PooledClusterSender(); } else if ("synchronous".equals(cluster.getSenderReplicationMode())) { sender = new SyncClusterSender(); } else if ("asynchronous".equals(cluster.getSenderReplicationMode()) || "fastasyncqueue".equals(cluster.getSenderReplicationMode())) { sender = new AsyncClusterSender(); } else { sender = new ClusterSender(); } ObjectName localSenderOName = senders[i]; sender.setAddress(JmxTools.getStringAttr(mBeanServer, localSenderOName, "address")); sender.setPort(JmxTools.getIntAttr(mBeanServer, localSenderOName, "port")); sender.setAvgMessageSize( JmxTools.getLongAttr(mBeanServer, localSenderOName, "avgMessageSize", -1)); sender.setAvgProcessingTime( JmxTools.getLongAttr(mBeanServer, localSenderOName, "avgProcessingTime", -1)); sender.setConnectCounter(JmxTools.getLongAttr(mBeanServer, localSenderOName, "connectCounter")); sender.setDisconnectCounter( JmxTools.getLongAttr(mBeanServer, localSenderOName, "disconnectCounter")); sender.setConnected( ((Boolean) mBeanServer.getAttribute(localSenderOName, "connected")).booleanValue()); sender.setKeepAliveTimeout( JmxTools.getLongAttr(mBeanServer, localSenderOName, "keepAliveTimeout")); sender.setNrOfRequests(JmxTools.getLongAttr(mBeanServer, localSenderOName, "nrOfRequests")); sender.setTotalBytes(JmxTools.getLongAttr(mBeanServer, localSenderOName, "totalBytes")); sender.setResend( ((Boolean) mBeanServer.getAttribute(localSenderOName, "resend")).booleanValue()); sender.setSuspect( ((Boolean) mBeanServer.getAttribute(localSenderOName, "suspect")).booleanValue()); if (sender instanceof PooledClusterSender) { ((PooledClusterSender) sender).setMaxPoolSocketLimit( JmxTools.getIntAttr(mBeanServer, localSenderOName, "maxPoolSocketLimit")); } if (sender instanceof SyncClusterSender) { SyncClusterSender syncSender = (SyncClusterSender) sender; syncSender.setDataFailureCounter( JmxTools.getLongAttr(mBeanServer, localSenderOName, "dataFailureCounter")); syncSender.setDataResendCounter( JmxTools.getLongAttr(mBeanServer, localSenderOName, "dataResendCounter")); syncSender.setSocketOpenCounter( JmxTools.getIntAttr(mBeanServer, localSenderOName, "socketOpenCounter")); syncSender.setSocketCloseCounter( JmxTools.getIntAttr(mBeanServer, localSenderOName, "socketCloseCounter")); syncSender.setSocketOpenFailureCounter( JmxTools.getIntAttr(mBeanServer, localSenderOName, "socketOpenFailureCounter")); } if (sender instanceof AsyncClusterSender) { AsyncClusterSender asyncSender = (AsyncClusterSender) sender; asyncSender.setInQueueCounter( JmxTools.getLongAttr(mBeanServer, localSenderOName, "inQueueCounter")); asyncSender.setOutQueueCounter( JmxTools.getLongAttr(mBeanServer, localSenderOName, "outQueueCounter")); asyncSender.setQueueSize(JmxTools.getIntAttr(mBeanServer, localSenderOName, "queueSize")); asyncSender.setQueuedNrOfBytes( JmxTools.getLongAttr(mBeanServer, localSenderOName, "queuedNrOfBytes")); } cluster.getMembers().add(sender); } } } return cluster; }