List of usage examples for java.lang.management ManagementFactory newPlatformMXBeanProxy
public static <T> T newPlatformMXBeanProxy(MBeanServerConnection connection, String mxbeanName, Class<T> mxbeanInterface) throws java.io.IOException
From source file:jsdp.app.control.clqg.univariate.CLQG.java
public static void main(String args[]) { /******************************************************************* * Problem parameters/*from ww w . java 2s . com*/ */ int T = 20; // Horizon length double G = 1; // Input transition double Phi = 1; // State transition double R = 1; // Input cost double Q = 1; // State cost double Ulb = -1; // Action constraint double Uub = 20; // Action constraint double noiseStd = 5; // Standard deviation of the noise double[] noiseStdArray = new double[T]; Arrays.fill(noiseStdArray, noiseStd); double truncationQuantile = 0.975; // Random variables Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(noiseStdArray.length) .mapToObj(i -> new NormalDist(0, noiseStdArray[i])) .toArray(Distribution[]::new); double[] supportLB = IntStream.iterate(0, i -> i + 1).limit(T) .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], 1 - truncationQuantile)).toArray(); double[] supportUB = IntStream.iterate(0, i -> i + 1).limit(T) .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], truncationQuantile)).toArray(); double initialX = 0; // Initial state /******************************************************************* * Model definition */ // State space double stepSize = 0.5; //Stepsize must be 1 for discrete distributions double minState = -25; double maxState = 100; StateImpl.setStateBoundaries(stepSize, minState, maxState); // Actions Function<State, ArrayList<Action>> buildActionList = (Function<State, ArrayList<Action>> & Serializable) s -> { StateImpl state = (StateImpl) s; ArrayList<Action> feasibleActions = new ArrayList<Action>(); double maxAction = Math.min(Uub, (StateImpl.getMaxState() - Phi * state.getInitialState()) / G); double minAction = Math.max(Ulb, (StateImpl.getMinState() - Phi * state.getInitialState()) / G); for (double actionPointer = minAction; actionPointer <= maxAction; actionPointer += StateImpl .getStepSize()) { feasibleActions.add(new ActionImpl(state, actionPointer)); } return feasibleActions; }; Function<State, Action> idempotentAction = (Function<State, Action> & Serializable) s -> new ActionImpl(s, 0.0); ImmediateValueFunction<State, Action, Double> immediateValueFunction = (initialState, action, finalState) -> { ActionImpl a = (ActionImpl) action; StateImpl fs = (StateImpl) finalState; double inputCost = Math.pow(a.getAction(), 2) * R; double stateCost = Math.pow(fs.getInitialState(), 2) * Q; return inputCost + stateCost; }; // Random Outcome Function RandomOutcomeFunction<State, Action, Double> randomOutcomeFunction = (initialState, action, finalState) -> { double realizedNoise = ((StateImpl) finalState).getInitialState() - ((StateImpl) initialState).getInitialState() * Phi - ((ActionImpl) action).getAction() * G; return realizedNoise; }; /******************************************************************* * Solve */ // Sampling scheme SamplingScheme samplingScheme = SamplingScheme.NONE; int maxSampleSize = 50; double reductionFactorPerStage = 1; // Value Function Processing Method: backward recursion double discountFactor = 1.0; int stateSpaceLowerBound = 10000000; float loadFactor = 0.8F; BackwardRecursionImpl recursion = new BackwardRecursionImpl(OptimisationDirection.MIN, distributions, supportLB, supportUB, immediateValueFunction, randomOutcomeFunction, buildActionList, idempotentAction, discountFactor, samplingScheme, maxSampleSize, reductionFactorPerStage, stateSpaceLowerBound, loadFactor, HashType.THASHMAP); System.out.println("--------------Backward recursion--------------"); StopWatch timer = new StopWatch(); OperatingSystemMXBean osMBean; try { osMBean = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class); long nanoBefore = System.nanoTime(); long cpuBefore = osMBean.getProcessCpuTime(); timer.start(); recursion.runBackwardRecursionMonitoring(); timer.stop(); long cpuAfter = osMBean.getProcessCpuTime(); long nanoAfter = System.nanoTime(); long percent; if (nanoAfter > nanoBefore) percent = ((cpuAfter - cpuBefore) * 100L) / (nanoAfter - nanoBefore); else percent = 0; System.out.println( "Cpu usage: " + percent + "% (" + Runtime.getRuntime().availableProcessors() + " cores)"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(); double ETC = recursion.getExpectedCost(initialX); StateDescriptorImpl initialState = new StateDescriptorImpl(0, initialX); double action = recursion.getOptimalAction(initialState).getAction(); System.out.println("Expected total cost (assuming an initial state " + initialX + "): " + ETC); System.out.println("Optimal initial action: " + action); System.out.println("Time elapsed: " + timer); System.out.println(); }
From source file:org.wso2.carbon.integration.test.client.JMXAnalyzerClient.java
public static int getThreadCount(String host, String port) throws IOException { String username = "admin"; String password = "admin"; int threadCount = 0; String threadName = "JMSThreads"; JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); Map<String, String[]> env = new HashMap<String, String[]>(); ThreadInfo threadIDInfo;/* w w w .j av a2s . com*/ String[] credentials = { username, password }; env.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); final ThreadMXBean remoteThread = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConnection, ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class); long[] allThreadIDsArray = remoteThread.getAllThreadIds(); //get jms thread count for (long threadID : allThreadIDsArray) { threadIDInfo = remoteThread.getThreadInfo(threadID); if (threadIDInfo != null && threadIDInfo.getThreadName() != null && threadIDInfo.getThreadName().startsWith(threadName)) { threadCount++; } } //close the connection jmxConnector.close(); return threadCount; }
From source file:test.integ.be.fedict.hsm.MonitoringTest.java
@Test public void testJMXConnection() throws Exception { JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:remoting-jmx://localhost:9999"); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL); MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); MemoryMXBean memoryMXBean = ManagementFactory.newPlatformMXBeanProxy(connection, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); LOG.debug("used heap memory: " + heapMemoryUsage.getUsed()); }
From source file:ca.simplegames.micro.controllers.StatsController.java
public void execute(MicroContext context, Map configuration) throws ControllerException { Map<String, Object> systemInfo = new HashMap<String, Object>(); Map<String, Object> osMap = new HashMap<String, Object>(); MBeanServerConnection mbeanServer = ManagementFactory.getPlatformMBeanServer(); OperatingSystemMXBean sunOperatingSystemMXBean = null; try {/*from ww w .java 2s . c o m*/ sunOperatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(mbeanServer, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class); } catch (IOException e) { throw new ControllerException(e.getMessage()); } Runtime rt = Runtime.getRuntime(); long totalMemory = rt.totalMemory() / MEGA_BYTE; long freeMemory = rt.freeMemory() / MEGA_BYTE; long usedMemory = totalMemory - freeMemory; final long p100 = (int) Math.round(((double) freeMemory / (double) totalMemory) * 100); Map<String, Long> memInfo = new HashMap<String, Long>(); memInfo.put("total", totalMemory); memInfo.put("used", usedMemory); memInfo.put("free", freeMemory); memInfo.put("percent_free", p100); systemInfo.put("memory", memInfo); systemInfo.put("powered_by", POWERED_BY_MICRO); //cpu usage in milli secs long currentCpuUsage = sunOperatingSystemMXBean.getProcessCpuTime() / 1000000; osMap.put("cpu_usage", currentCpuUsage); osMap.put("available_processors", sunOperatingSystemMXBean.getAvailableProcessors()); osMap.put("system_load_average", sunOperatingSystemMXBean.getSystemLoadAverage()); osMap.put("committed_virtual_memory_size", sunOperatingSystemMXBean.getCommittedVirtualMemorySize()); osMap.put("free_physical_memory_size", sunOperatingSystemMXBean.getFreePhysicalMemorySize()); osMap.put("total_physical_memory_size", sunOperatingSystemMXBean.getTotalPhysicalMemorySize()); osMap.put("free_swap_space_size", sunOperatingSystemMXBean.getFreeSwapSpaceSize()); osMap.put("total_swap_space_size", sunOperatingSystemMXBean.getTotalSwapSpaceSize()); systemInfo.put("os", osMap); List<GarbageCollectorMXBean> gc = ManagementFactory.getGarbageCollectorMXBeans(); List<Map> gcInfo = new ArrayList<Map>(); for (GarbageCollectorMXBean aGc : gc) { Map<String, Object> gcMap = new HashMap<String, Object>(); gcMap.put("name", aGc.getName()); gcMap.put("collection_count", aGc.getCollectionCount()); gcMap.put("collection_time", aGc.getCollectionTime()); gcInfo.add(gcMap); } systemInfo.put("gc", gcInfo); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); Map<String, Object> threadInfoMap = new HashMap<String, Object>(); // more to come ;) threadInfoMap.put("peak_thread_count", threadMXBean.getPeakThreadCount()); threadInfoMap.put("thread_count", threadMXBean.getThreadCount()); threadInfoMap.put("total_started_thread_count", threadMXBean.getTotalStartedThreadCount()); long[] deadlockedThreads = threadMXBean.findMonitorDeadlockedThreads(); threadInfoMap.put("dead_locked_thread_count", deadlockedThreads != null ? deadlockedThreads.length : 0); systemInfo.put("thread_info", threadInfoMap); JSONObject sysinfoJson = new JSONObject(Collections.singletonMap("system_info", systemInfo)); String sysinfoString = null; try { sysinfoString = context.getRequest().getParameter("pretty") != null ? sysinfoJson.toString(2) : sysinfoJson.toString(); } catch (JSONException e) { e.printStackTrace(); throw new ControllerException(e.getMessage()); } context.getRackResponse().withContentType(Mime.mimeType(JSON_TYPE)).withBody(sysinfoString) .withContentLength(sysinfoString.length()).with(Rack.MESSAGE_STATUS, HttpServletResponse.SC_OK); context.halt(); }
From source file:org.apache.hadoop.hive.ql.debug.Utils.java
/** * Dumps process heap./* w ww .java 2s. c o m*/ * @param fileName File name to use. * @param live Whether to only dump live objects. */ public static void dumpHeap(String fileName, boolean live) { if (hotspotMBean == null) { try { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); hotspotMBean = ManagementFactory.newPlatformMXBeanProxy(server, HOTSPOT_BEAN_NAME, HOTSPOT_MXBEAN_CLASS); } catch (IOException e) { LOG.error(e.getMessage()); throw new RuntimeException(e); } } if (DUMP_HEAP_METHOD != null) { try { DUMP_HEAP_METHOD.invoke(hotspotMBean, new Object[] { fileName, Boolean.valueOf(live) }); } catch (RuntimeException re) { LOG.error(re.getMessage()); throw re; } catch (Exception exp) { LOG.error(exp.getMessage()); throw new RuntimeException(exp); } } else { LOG.error("Cannot find method dumpHeap() in com.sun.management.HotSpotDiagnosticMXBean."); } }
From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java
public static boolean connect(int i) { JMXConnector jmxc = null;/*from ww w. j av a 2 s .c o m*/ JMXServiceURL url = null; try { url = new JMXServiceURL(MXBeanRegisterer.ADDRESS + i); jmxc = JMXConnectorFactory.connect(url, null); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { return false; // System.out.println("Could not connect to address: " + url); // e.printStackTrace(); } if (jmxc != null) { try { MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName objectName = new ObjectName(MXBeanRegisterer.OBJECT_NAME); Object numberOfMutations = mbsc.getAttribute(objectName, "NumberOfMutations"); Object currentTest = mbsc.getAttribute(objectName, "CurrentTest"); Object currentMutation = mbsc.getAttribute(objectName, "CurrentMutation"); Object allMutations = mbsc.getAttribute(objectName, "Mutations"); Object mutationsDuration = mbsc.getAttribute(objectName, "MutationDuration"); Object testDuration = mbsc.getAttribute(objectName, "TestDuration"); // Object mutationSummary = mbsc.getAttribute(objectName, // "MutationSummary"); final RuntimeMXBean remoteRuntime = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); final MemoryMXBean remoteMemory = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); System.out.print("Connection: " + i + " "); System.out.println("Target VM: " + remoteRuntime.getName() + " - " + remoteRuntime.getVmVendor() + " - " + remoteRuntime.getSpecVersion() + " - " + remoteRuntime.getVmVersion()); System.out.println( "Running for: " + DurationFormatUtils.formatDurationHMS(remoteRuntime.getUptime())); System.out .println("Memory usage: Heap - " + formatMemory(remoteMemory.getHeapMemoryUsage().getUsed()) + " Non Heap - " + formatMemory(remoteMemory.getNonHeapMemoryUsage().getUsed())); String mutationDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(mutationsDuration.toString())); String testDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(testDuration.toString())); if (DEBUG_ADD) { System.out.println("Classpath: " + remoteRuntime.getClassPath()); System.out.println("Args: " + remoteRuntime.getInputArguments()); System.out.println("All Mutations: " + allMutations); } // System.out.println(mutationSummary); System.out.println( "Current mutation (Running for: " + mutationDurationFormatted + "): " + currentMutation); System.out.println("Mutations tested: " + numberOfMutations); System.out.println("Current test: (Running for: " + testDurationFormatted + "): " + currentTest); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (MalformedObjectNameException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (AttributeNotFoundException e) { e.printStackTrace(); } catch (InstanceNotFoundException e) { e.printStackTrace(); } catch (MBeanException e) { e.printStackTrace(); } catch (ReflectionException e) { e.printStackTrace(); } finally { try { jmxc.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; }
From source file:lineage2.gameserver.network.telnet.commands.TelnetPerfomance.java
/** * Constructor for TelnetPerfomance./*from w w w. jav a2 s. c o m*/ */ public TelnetPerfomance() { _commands.add(new TelnetCommand("pool", "p") { @Override public String getUsage() { return "pool [dump]"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); if ((args.length == 0) || args[0].isEmpty()) { sb.append(ThreadPoolManager.getInstance().getStats()); } else if (args[0].equals("dump") || args[0].equals("d")) { try { new File("stats").mkdir(); FileUtils .writeStringToFile( new File("stats/RunnableStats-" + new SimpleDateFormat("MMddHHmmss") .format(System.currentTimeMillis()) + ".txt"), RunnableStatsManager.getInstance().getStats().toString()); sb.append("Runnable stats saved.\n"); } catch (IOException e) { sb.append("Exception: " + e.getMessage() + "!\n"); } } else { return null; } return sb.toString(); } }); _commands.add(new TelnetCommand("mem", "m") { @Override public String getUsage() { return "mem"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); sb.append(StatsUtils.getMemUsage()); return sb.toString(); } }); _commands.add(new TelnetCommand("heap") { @Override public String getUsage() { return "heap [dump] <live>"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); if ((args.length == 0) || args[0].isEmpty()) { return null; } else if (args[0].equals("dump") || args[0].equals("d")) { try { boolean live = (args.length == 2) && !args[1].isEmpty() && (args[1].equals("live") || args[1].equals("l")); new File("dumps").mkdir(); String filename = "dumps/HeapDump" + (live ? "Live" : "") + "-" + new SimpleDateFormat("MMddHHmmss").format(System.currentTimeMillis()) + ".hprof"; MBeanServer server = ManagementFactory.getPlatformMBeanServer(); HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class); bean.dumpHeap(filename, live); sb.append("Heap dumped.\n"); } catch (IOException e) { sb.append("Exception: " + e.getMessage() + "!\n"); } } else { return null; } return sb.toString(); } }); _commands.add(new TelnetCommand("threads", "t") { @Override public String getUsage() { return "threads [dump]"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); if ((args.length == 0) || args[0].isEmpty()) { sb.append(StatsUtils.getThreadStats()); } else if (args[0].equals("dump") || args[0].equals("d")) { try { new File("stats").mkdir(); FileUtils .writeStringToFile( new File("stats/ThreadsDump-" + new SimpleDateFormat("MMddHHmmss") .format(System.currentTimeMillis()) + ".txt"), StatsUtils.getThreadStats(true, true, true).toString()); sb.append("Threads stats saved.\n"); } catch (IOException e) { sb.append("Exception: " + e.getMessage() + "!\n"); } } else { return null; } return sb.toString(); } }); _commands.add(new TelnetCommand("gc") { @Override public String getUsage() { return "gc"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); sb.append(StatsUtils.getGCStats()); return sb.toString(); } }); _commands.add(new TelnetCommand("net", "ns") { @Override public String getUsage() { return "net"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); sb.append(SelectorThread.getStats()); return sb.toString(); } }); _commands.add(new TelnetCommand("pathfind", "pfs") { @Override public String getUsage() { return "pathfind"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); sb.append(PathFindBuffers.getStats()); return sb.toString(); } }); _commands.add(new TelnetCommand("dbstats", "ds") { @Override public String getUsage() { return "dbstats"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); sb.append("Basic database usage\n"); sb.append("=================================================\n"); sb.append("Connections").append('\n'); sb.append(" Busy: ........................ ") .append(DatabaseFactory.getInstance().getBusyConnectionCount()).append('\n'); sb.append(" Idle: ........................ ") .append(DatabaseFactory.getInstance().getIdleConnectionCount()).append('\n'); sb.append("Players").append('\n'); sb.append(" Update: ...................... ").append(GameStats.getUpdatePlayerBase()) .append('\n'); double cacheHitCount, cacheMissCount, cacheHitRatio; Cache cache; LiveCacheStatistics cacheStats; JdbcEntityStats entityStats; cache = ItemsDAO.getInstance().getCache(); cacheStats = cache.getLiveCacheStatistics(); entityStats = ItemsDAO.getInstance().getStats(); cacheHitCount = cacheStats.getCacheHitCount(); cacheMissCount = cacheStats.getCacheMissCount(); cacheHitRatio = cacheHitCount / (cacheHitCount + cacheMissCount); sb.append("Items").append('\n'); sb.append(" getLoadCount: ................ ").append(entityStats.getLoadCount()).append('\n'); sb.append(" getInsertCount: .............. ").append(entityStats.getInsertCount()).append('\n'); sb.append(" getUpdateCount: .............. ").append(entityStats.getUpdateCount()).append('\n'); sb.append(" getDeleteCount: .............. ").append(entityStats.getDeleteCount()).append('\n'); sb.append("Cache").append('\n'); sb.append(" getPutCount: ................. ").append(cacheStats.getPutCount()).append('\n'); sb.append(" getUpdateCount: .............. ").append(cacheStats.getUpdateCount()).append('\n'); sb.append(" getRemovedCount: ............. ").append(cacheStats.getRemovedCount()).append('\n'); sb.append(" getEvictedCount: ............. ").append(cacheStats.getEvictedCount()).append('\n'); sb.append(" getExpiredCount: ............. ").append(cacheStats.getExpiredCount()).append('\n'); sb.append(" getSize: ..................... ").append(cacheStats.getSize()).append('\n'); sb.append(" getLocalHeapSize: ............. ").append(cacheStats.getLocalHeapSize()) .append('\n'); sb.append(" getLocalDiskSize: ............... ").append(cacheStats.getLocalDiskSize()) .append('\n'); sb.append(" cacheHitRatio: ............... ").append(String.format("%2.2f", cacheHitRatio)) .append('\n'); sb.append("=================================================\n"); cache = MailDAO.getInstance().getCache(); cacheStats = cache.getLiveCacheStatistics(); entityStats = MailDAO.getInstance().getStats(); cacheHitCount = cacheStats.getCacheHitCount(); cacheMissCount = cacheStats.getCacheMissCount(); cacheHitRatio = cacheHitCount / (cacheHitCount + cacheMissCount); sb.append("Mail").append('\n'); sb.append(" getLoadCount: ................ ").append(entityStats.getLoadCount()).append('\n'); sb.append(" getInsertCount: .............. ").append(entityStats.getInsertCount()).append('\n'); sb.append(" getUpdateCount: .............. ").append(entityStats.getUpdateCount()).append('\n'); sb.append(" getDeleteCount: .............. ").append(entityStats.getDeleteCount()).append('\n'); sb.append("Cache").append('\n'); sb.append(" getPutCount: ................. ").append(cacheStats.getPutCount()).append('\n'); sb.append(" getUpdateCount: .............. ").append(cacheStats.getUpdateCount()).append('\n'); sb.append(" getRemovedCount: ............. ").append(cacheStats.getRemovedCount()).append('\n'); sb.append(" getEvictedCount: ............. ").append(cacheStats.getEvictedCount()).append('\n'); sb.append(" getExpiredCount: ............. ").append(cacheStats.getExpiredCount()).append('\n'); sb.append(" getSize: ..................... ").append(cacheStats.getSize()).append('\n'); sb.append(" getLocalHeapSize: ............. ").append(cacheStats.getLocalHeapSize()) .append('\n'); sb.append(" getLocalDiskSize: ............... ").append(cacheStats.getLocalDiskSize()) .append('\n'); sb.append(" cacheHitRatio: ............... ").append(String.format("%2.2f", cacheHitRatio)) .append('\n'); sb.append("=================================================\n"); return sb.toString(); } }); _commands.add(new TelnetCommand("aistats", "as") { @Override public String getUsage() { return "aistats"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < Config.AI_TASK_MANAGER_COUNT; i++) { sb.append("AiTaskManager #").append(i + 1).append('\n'); sb.append("=================================================\n"); sb.append(AiTaskManager.getInstance().getStats(i)); sb.append("=================================================\n"); } return sb.toString(); } }); _commands.add(new TelnetCommand("effectstats", "es") { @Override public String getUsage() { return "effectstats"; } @Override public String handle(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < Config.EFFECT_TASK_MANAGER_COUNT; i++) { sb.append("EffectTaskManager #").append(i + 1).append('\n'); sb.append("=================================================\n"); sb.append(EffectTaskManager.getInstance().getStats(i)); sb.append("=================================================\n"); } return sb.toString(); } }); }
From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java
private RuntimeMXBean getRuntimeMXBean(MBeanServerConnection connection, String upTimeQuery) throws IOException { return ManagementFactory.newPlatformMXBeanProxy(connection, upTimeQuery, RuntimeMXBean.class); }
From source file:org.apache.cassandra.tools.NodeProbe.java
/** * Create a connection to the JMX agent and setup the M[X]Bean proxies. * * @throws IOException on connection failures *//* w w w . j a v a 2 s . c o m*/ private void connect() throws IOException { JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port)); Map<String, Object> env = new HashMap<String, Object>(); if (username != null) { String[] creds = { username, password }; env.put(JMXConnector.CREDENTIALS, creds); } env.put("com.sun.jndi.rmi.factory.socket", getRMIClientSocketFactory()); jmxc = JMXConnectorFactory.connect(jmxUrl, env); mbeanServerConn = jmxc.getMBeanServerConnection(); try { ObjectName name = new ObjectName(ssObjName); ssProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageServiceMBean.class); name = new ObjectName(MessagingService.MBEAN_NAME); msProxy = JMX.newMBeanProxy(mbeanServerConn, name, MessagingServiceMBean.class); name = new ObjectName(StreamManagerMBean.OBJECT_NAME); streamProxy = JMX.newMBeanProxy(mbeanServerConn, name, StreamManagerMBean.class); name = new ObjectName(CompactionManager.MBEAN_OBJECT_NAME); compactionProxy = JMX.newMBeanProxy(mbeanServerConn, name, CompactionManagerMBean.class); name = new ObjectName(FailureDetector.MBEAN_NAME); fdProxy = JMX.newMBeanProxy(mbeanServerConn, name, FailureDetectorMBean.class); name = new ObjectName(CacheService.MBEAN_NAME); cacheService = JMX.newMBeanProxy(mbeanServerConn, name, CacheServiceMBean.class); name = new ObjectName(StorageProxy.MBEAN_NAME); spProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageProxyMBean.class); name = new ObjectName(HintedHandOffManager.MBEAN_NAME); hhProxy = JMX.newMBeanProxy(mbeanServerConn, name, HintedHandOffManagerMBean.class); name = new ObjectName(GCInspector.MBEAN_NAME); gcProxy = JMX.newMBeanProxy(mbeanServerConn, name, GCInspectorMXBean.class); } catch (MalformedObjectNameException e) { throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); } memProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); runtimeProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); }
From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java
private long getFreeHeapMemory(MBeanServerConnection connection) throws MetricUnreachableException { try {//from www. j av a 2 s .c o m MemoryMXBean memoryBean = ManagementFactory.newPlatformMXBeanProxy(connection, "java.lang:type=Memory", MemoryMXBean.class); long max = memoryBean.getHeapMemoryUsage().getMax(); long used = memoryBean.getHeapMemoryUsage().getUsed(); return max - used; } catch (IOException e) { throw new MetricUnreachableException("Error retrieving Memory MBean" + e.getMessage(), e); } }