List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
From source file:com.l2jfree.L2Config.java
/** * Returns application lifetime in a short string. * /* w w w . ja va 2s .c o m*/ * @return time since launch */ public static String getShortUptime() { final long uptimeInSec = (long) Math.ceil(ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0); final long s = uptimeInSec / 1 % 60; final long m = uptimeInSec / 60 % 60; final long h = uptimeInSec / 3600 % 24; final long d = uptimeInSec / 86400; final L2TextBuilder tb = new L2TextBuilder(); if (d > 0) tb.append(d + "d"); if (h > 0 || tb.length() != 0) tb.append(h + "h"); if (m > 0 || tb.length() != 0) tb.append(m + "m"); if (s > 0 || tb.length() != 0) tb.append(s + "s"); return tb.moveToString(); }
From source file:info.debatty.jinu.CaseResult.java
/** * Initialize the case result.//w ww . j a v a 2 s .c o m */ public CaseResult() { try { this.hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex) { this.hostname = "Unknown"; } this.processors = Runtime.getRuntime().availableProcessors(); this.memory = Runtime.getRuntime().maxMemory(); this.time = System.currentTimeMillis(); this.sources = new HashMap<TestInterface, String>(); String classpath_string = ManagementFactory.getRuntimeMXBean().getSystemProperties().get(CLASSPATH_KEY); this.classpath = classpath_string.split(":"); }
From source file:org.apache.flink.runtime.util.EnvironmentInformation.java
public static String getJvmVersion() { try {//from ww w .j av a 2 s . c o m final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); return bean.getVmName() + " - " + bean.getVmVendor() + " - " + bean.getSpecVersion() + '/' + bean.getVmVersion(); } catch (Throwable t) { return UNKNOWN; } }
From source file:uk.ac.sanger.cgp.wwdocker.beans.WorkerResources.java
private void base_init(OperatingSystemMXBean osmxb) { String[] bits = ManagementFactory.getRuntimeMXBean().getName().split("@"); pid = Long.getLong(bits[0]);//w w w. j a v a 2s.c om totalMemBytes = osmxb.getTotalPhysicalMemorySize(); availableProcessors = Runtime.getRuntime().availableProcessors(); hostName = System.getenv("HOSTNAME"); if (hostName == null) { try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { throw new RuntimeException("Unable to determine hostname", e); } } }
From source file:gobblin.kafka.writer.KafkaDataWriterIntegrationTest.java
@Test public void testErrors() throws Exception { log.warn("Process id = " + ManagementFactory.getRuntimeMXBean().getName()); int numRecordsPerExtract = 5; int numParallel = 2; int errorEvery = 2000; int totalRecords = numRecordsPerExtract * numParallel; int totalSuccessful = totalRecords / errorEvery + totalRecords % errorEvery; {// w w w. j ava 2s . c o m Closer closer = Closer.create(); try { kafkaTestHelper.provisionTopic(TOPIC); jobProps.setProperty("source.numRecordsPerExtract", "" + numRecordsPerExtract); jobProps.setProperty("source.numParallelism", "" + numParallel); jobProps.setProperty("writer.kafka.producerConfig.flaky.errorType", "regex"); // all records from partition 0 will be dropped. jobProps.setProperty("writer.kafka.producerConfig.flaky.regexPattern", ":index:0.*"); jobProps.setProperty("job.commit.policy", "partial"); jobProps.setProperty("publish.at.job.level", "false"); totalSuccessful = 5; // number of records in partition 1 JobLauncher jobLauncher = closer .register(JobLauncherFactory.newJobLauncher(gobblinProps, jobProps)); jobLauncher.launchJob(null); } catch (Exception e) { } finally { closer.close(); } // test records written testRecordsWritten(totalSuccessful, TOPIC); } boolean trySecond = true; if (trySecond) { Closer closer = Closer.create(); try { jobProps.setProperty("source.numRecordsPerExtract", "" + numRecordsPerExtract); jobProps.setProperty("source.numParallelism", "" + numParallel); jobProps.setProperty("writer.kafka.producerConfig.flaky.errorType", "nth"); jobProps.setProperty("writer.kafka.producerConfig.flaky.errorEvery", "" + errorEvery); JobLauncher jobLauncher = closer .register(JobLauncherFactory.newJobLauncher(gobblinProps, jobProps)); jobLauncher.launchJob(null); totalSuccessful = totalRecords / errorEvery + totalRecords % errorEvery; } catch (Exception e) { } finally { closer.close(); } } // test records written testRecordsWritten(totalSuccessful, TOPIC); }
From source file:com.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page./*from ww w . j a v a 2s.c o m*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); TemplateEngine.getInstance() .render(TemplateContext.builder().request(req).response(resp).template(TOOLS_TEMPLATE) .locale(req.getLocale()) .templateData(TemplateData.newTemplateData().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()) .put("totalBundles", bundles.length).put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }
From source file:io.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page./*from w ww . j a v a 2 s .c o m*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); TemplateEngines.getDefault().render(TemplateContext.builder().request(req).response(resp) .template(TOOLS_TEMPLATE).locale(req.getLocale()) .contextObject(ContextObject.newContextObject().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()).put("totalBundles", bundles.length) .put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }
From source file:com.amazonaws.services.simpleworkflow.flow.worker.DecisionTaskPoller.java
public DecisionTaskPoller() { identity = ManagementFactory.getRuntimeMXBean().getName(); }
From source file:org.slc.sli.ingestion.IngestionHealthCheck.java
public String getStartTime() { //Start Time//from w w w .ja v a 2s . c om RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); long startTimeLong = bean.getStartTime(); return convertEpochTimeToDateTime(startTimeLong); }
From source file:org.pepstock.jem.node.NodeInfoUtility.java
/** * Factory creates a NodeInfo copying a set of information from Member * object of Hazelcast framework. NodeInfo will use Uuid of Member as the * key.//from w w w . ja va 2 s . co m * * @see org.pepstock.jem.node.NodeInfo * @param member member object of Hazelcast framework * @param info node info to load * @throws NodeException if any exception occurs */ public static final void loadNodeInfo(Member member, NodeInfo info) throws NodeException { String jemVersion = getManifestAttribute(ConfigKeys.JEM_MANIFEST_VERSION); // sets the version if (jemVersion != null) { info.setJemVersion(jemVersion); } // set uuid of member of hazelcast as key info.setKey(member.getUuid()); // set status starting at the beginning info.setStatus(Status.STARTING); // sets boolean if has affinity loader // for net info of member, loads all info inside of nodeinfo // port of RMI will be set later InetSocketAddress address = member.getInetSocketAddress(); info.setPort(address.getPort()); info.setIpaddress(address.getAddress().getHostAddress()); // sets label to be displayed by GRS info.setLabel(info.getIpaddress() + ":" + info.getPort()); // sets execution environment info.setExecutionEnvironment(Main.EXECUTION_ENVIRONMENT); // use JMX to extract current process id info.setProcessId(ManagementFactory.getRuntimeMXBean().getName()); // extracts the name using the MXBean result String hostname = StringUtils.substringAfter(info.getProcessId(), "@"); info.setHostname(hostname); // extracts from operating ssytem MXbean all info about the ssytem OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean(); info.getNodeInfoBean().setSystemArchitecture(bean.getArch()); info.getNodeInfoBean().setAvailableProcessors(bean.getAvailableProcessors()); info.getNodeInfoBean().setSystemName(bean.getName()); // uses SIGAR to get total memory and the user used by JEM to start try { info.getNodeInfoBean().setTotalMemory(SIGAR.getMem().getTotal()); ProcCredName cred = SIGAR.getProcCredName(SIGAR.getPid()); info.setUser(cred.getUser()); } catch (SigarException e) { throw new NodeException(e.getMessage(), e); } // informs the node itself that it has been loaded info.loaded(); }