List of usage examples for java.lang.management RuntimeMXBean getStartTime
public long getStartTime();
From source file:org.apache.syncope.core.logic.SyncopeLogic.java
private void initSystemInfo() { if (SYSTEM_INFO == null) { OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); SYSTEM_INFO = new SystemInfo(); try {/*from w ww. j ava2 s .c o m*/ SYSTEM_INFO.setHostname(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { LOG.error("Could not get host name", e); } SYSTEM_INFO.setOs(operatingSystemMXBean.getName() + " " + operatingSystemMXBean.getVersion() + " " + operatingSystemMXBean.getArch()); SYSTEM_INFO.setAvailableProcessors(operatingSystemMXBean.getAvailableProcessors()); SYSTEM_INFO.setJvm(runtimeMXBean.getVmName() + " " + System.getProperty("java.version") + " " + runtimeMXBean.getVmVendor()); SYSTEM_INFO.setStartTime(runtimeMXBean.getStartTime()); } }
From source file:org.fluentd.jvmwatcher.data.JvmWatchState.java
/** * @param clientPrixy//ww w . jav a 2 s . c om * @return */ public static JvmWatchState makeJvmWatchState(JvmClientProxy clientProxy) { // null check if (null == clientProxy) { return null; } if (null == clientProxy.getLocalJvmInfo()) { return null; } // create data object JvmWatchState ret = new JvmWatchState(); // set Local JVM Information ret.commandLine_ = clientProxy.getLocalJvmInfo().getCommandLine_(); ret.displayName_ = clientProxy.getLocalJvmInfo().getDisplayName(); ret.jvmId_ = clientProxy.getLocalJvmInfo().getJvmid(); ret.shortName_ = clientProxy.getLocalJvmInfo().getShortName(); // create log line array ret.stateLog_ = new ArrayList<JvmStateLog>(); // set JVM information try { // CompilationMXBean CompilationMXBean compilationBean = clientProxy.getCompilationMXBean(); if (null != compilationBean) { ret.jitName_ = compilationBean.getName(); } // OperatingSystemMXBean OperatingSystemMXBean OpeSysBean = clientProxy.getOperatingSystemMXBean(); if (null != OpeSysBean) { ret.osArch_ = OpeSysBean.getArch(); ret.osName_ = OpeSysBean.getName(); ret.osVersion_ = OpeSysBean.getVersion(); } // RuntimeMXBean RuntimeMXBean runtimeBean = clientProxy.getRuntimeMXBean(); if (null != runtimeBean) { ret.jvmStartTime_ = runtimeBean.getStartTime(); ret.jvmRuntimeName_ = runtimeBean.getName(); ret.vmName_ = runtimeBean.getVmName(); ret.vmVender_ = runtimeBean.getVmVendor(); ret.vmVersion_ = runtimeBean.getVmVersion(); ret.specName_ = runtimeBean.getSpecName(); ret.specVender_ = runtimeBean.getSpecVendor(); ret.specVersion_ = runtimeBean.getSpecVersion(); } } catch (IOException ex) { log.error("get MXBean error.", ex); // close JvmClientProxy clientProxy.disconnect(); } catch (Exception ex) { log.error("get MXBean error.", ex); // close JvmClientProxy clientProxy.disconnect(); } return ret; }
From source file:org.jwebsocket.plugins.system.SystemPlugIn.java
private void getJVMInfo(WebSocketConnector aConnector, Token aToken) { // check if user is allowed to run 'getjvminfo' command if (!hasAuthority(aConnector, NS_SYSTEM + ".getjvminfo")) { sendToken(aConnector, aConnector, createAccessDenied(aToken)); return;/*ww w . j av a2s. co m*/ } Token lResponse = createResponse(aToken); RuntimeMXBean lBean = ManagementFactory.getRuntimeMXBean(); MemoryMXBean lMemory = ManagementFactory.getMemoryMXBean(); OperatingSystemMXBean lOS = ManagementFactory.getOperatingSystemMXBean(); lResponse.setMap("data", new MapAppender().append("inputArguments", lBean.getInputArguments()) .append("libraryPath", lBean.getLibraryPath()) .append("managementSpecVersion", lBean.getManagementSpecVersion()).append("name", lBean.getName()) .append("specName", lBean.getSpecName()).append("specVendor", lBean.getSpecVendor()) .append("specVersion", lBean.getSpecVersion()).append("startTime", lBean.getStartTime()) .append("systemProperties", lBean.getSystemProperties()).append("uptime", lBean.getUptime()) .append("vmName", lBean.getVmName()).append("vmVendor", lBean.getVmVendor()) .append("vmVersion", lBean.getVmVersion()).append("classPath", lBean.getClassPath()) .append("osArch", lOS.getArch()).append("osAvailableProcessors", lOS.getAvailableProcessors()) .append("osName", lOS.getName()).append("osVersion", lOS.getVersion()) .append("osLoadAverage", lOS.getSystemLoadAverage()) .append("heapMemoryUsed", lMemory.getHeapMemoryUsage().getUsed()) .append("heapMemoryMax", lMemory.getHeapMemoryUsage().getMax()) .append("heapMemoryInit", lMemory.getHeapMemoryUsage().getInit()) .append("nonheapMemoryInit", lMemory.getNonHeapMemoryUsage().getInit()) .append("nonheapMemoryMax", lMemory.getNonHeapMemoryUsage().getMax()) .append("nonheapMemoryUsed", lMemory.getNonHeapMemoryUsage().getUsed()).getMap()); sendToken(aConnector, lResponse); }
From source file:org.liferayhub.pc.service.impl.PowerConsoleServiceImpl.java
public String runCommand(long userId, long companyId, String mode, String command) { String response = ""; Date startDate = new Date(); if ("server".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\t\tShow this help message\n" + "version\t\t Display the version of the Liferay Portal\n" + "date\t\t\tDisplay the date and time of the database server\n" + "uptime\t\t Display the uptime of the portal\n" + "adduser\t\t Add a new user"; } else if ("version".equalsIgnoreCase(command)) { response = ReleaseInfo.getReleaseInfo() + " running on " + StringUtil.upperCaseFirstLetter(ServerDetector.getServerId()); } else if ("date".equalsIgnoreCase(command)) { response = new Date().toString(); } else if ("uptime".equalsIgnoreCase(command)) { response = getUptime(PortalUtil.getUptime().getTime()); } else if (command.toLowerCase().startsWith("adduser")) { response = handleAddUser(userId, companyId, command); }//from w w w . ja va 2 s.c o m } else if ("db".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\t\tShow this help message\n" + "version\t\t Display the version of the database\n" + "date\t\t\tDisplay the date and time of the database server\n" + "<sql query>\t Display result of any SQL query"; } else if ("date".equalsIgnoreCase(command)) { response = runSQLQuery("select now() \"\""); } else if ("version".equalsIgnoreCase(command)) { response = runSQLQuery( "select '" + DBFactoryUtil.getDBFactory().getDB().getType() + "' as '', version() ''"); } else response = runSQLQuery(command); } else if ("jvm".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\tShow this help message\n" + "mem\t\t Display memory usage of the JVM\n" + "osinfo\t Display operating system info of the running JVM\n" + "vminfo\t Display VM info"; } else if ("mem".equalsIgnoreCase(command)) { MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); response = "Heap : " + mem.getHeapMemoryUsage().toString(); response += "\nNon Heap : " + mem.getNonHeapMemoryUsage().toString(); response += "\nFinalization: " + mem.getObjectPendingFinalizationCount() + " objects pending"; } else if ("osinfo".equalsIgnoreCase(command)) { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); response = os.getName() + "[" + os.getArch() + "] " + os.getVersion() + " (" + os.getAvailableProcessors() + " processors)"; response += "\nLoad Average: " + os.getSystemLoadAverage(); } else if ("vminfo".equalsIgnoreCase(command)) { RuntimeMXBean vm = ManagementFactory.getRuntimeMXBean(); response = vm.getVmName() + " " + vm.getVmVersion() + " by " + vm.getVmVendor(); response += "\n" + vm.getSpecName() + " " + vm.getSpecVersion() + " by " + vm.getSpecVendor(); response += "\nStarted at: " + DateFormat.getInstance().format(new Date(vm.getStartTime())); response += "\nUptime : " + getUptime(vm.getStartTime()); } else { response = UNRECOGNIZED_COMMAND; } } // save command to database if it is not 'help' if (!command.startsWith("help")) { try { // add to history Date endDate = new Date(); long id = CounterLocalServiceUtil.increment(CommandHistory.class.getName()); CommandHistory history = CommandHistoryLocalServiceUtil.createCommandHistory(id); history.setCommand(command); history.setExecutionDate(startDate); history.setExecutionTime(endDate.getTime() - startDate.getTime()); history.setMode(mode); history.setUserId(userId); CommandHistoryLocalServiceUtil.updateCommandHistory(history); // TODO: delete the oldest entry > MAX_HISTORY_SIZE // get the history size long historySize = 100; List<CommandHistory> historyList = CommandHistoryLocalServiceUtil .findCommandHistoryByUserId(userId); if (historyList.size() >= historySize) { CommandHistoryLocalServiceUtil.deleteCommandHistory(historyList.get(0)); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } } return response; }
From source file:org.slc.sli.ingestion.IngestionHealthCheck.java
public String getStartTime() { //Start Time/*from w ww .java 2 s .c o m*/ RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); long startTimeLong = bean.getStartTime(); return convertEpochTimeToDateTime(startTimeLong); }