use of java.lang.management.OperatingSystemMXBean in project gerrit by GerritCodeReview.
the class GetSummary method getJvmSummary.
private JvmSummaryInfo getJvmSummary() {
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
JvmSummaryInfo jvmSummary = new JvmSummaryInfo();
jvmSummary.vmVendor = runtimeBean.getVmVendor();
jvmSummary.vmName = runtimeBean.getVmName();
jvmSummary.vmVersion = runtimeBean.getVmVersion();
jvmSummary.osName = osBean.getName();
jvmSummary.osVersion = osBean.getVersion();
jvmSummary.osArch = osBean.getArch();
jvmSummary.user = System.getProperty("user.name");
try {
jvmSummary.host = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
// Ignored
}
jvmSummary.currentWorkingDirectory = path(Paths.get(".").toAbsolutePath().getParent());
jvmSummary.site = path(sitePath);
return jvmSummary;
}
use of java.lang.management.OperatingSystemMXBean in project hazelcast by hazelcast.
the class PhoneHomeTest method testPhoneHomeParameters.
@Test
public void testPhoneHomeParameters() {
sleepAtLeastMillis(1);
Map<String, String> parameters = phoneHome.phoneHome(true);
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
assertEquals(parameters.get(PhoneHomeMetrics.BUILD_VERSION.getRequestParameterName()), BuildInfoProvider.getBuildInfo().getVersion());
assertTrue(parameters.get(PhoneHomeMetrics.JAVA_CLASSPATH.getRequestParameterName()).endsWith(".jar"));
assertEquals(UUID.fromString(parameters.get(PhoneHomeMetrics.UUID_OF_CLUSTER.getRequestParameterName())), node.getLocalMember().getUuid());
assertNull(parameters.get("e"));
assertNull(parameters.get("oem"));
assertNull(parameters.get("l"));
assertNull(parameters.get("hdgb"));
assertEquals(parameters.get(PhoneHomeMetrics.HAZELCAST_DOWNLOAD_ID.getRequestParameterName()), "source");
assertEquals(parameters.get(PhoneHomeMetrics.CLUSTER_SIZE.getRequestParameterName()), "A");
assertEquals(parameters.get(PhoneHomeMetrics.EXACT_CLUSTER_SIZE.getRequestParameterName()), "1");
assertEquals(parameters.get(PhoneHomeMetrics.PARTITION_COUNT.getRequestParameterName()), "271");
assertEquals(parameters.get(PhoneHomeMetrics.CLIENT_ENDPOINT_COUNT.getRequestParameterName()), "A");
assertEquals(parameters.get(PhoneHomeMetrics.ACTIVE_CPP_CLIENTS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.ACTIVE_CSHARP_CLIENTS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.ACTIVE_JAVA_CLIENTS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.ACTIVE_NODEJS_CLIENTS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.ACTIVE_PYTHON_CLIENTS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.ACTIVE_GO_CLIENTS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.OPENED_CPP_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.OPENED_CSHARP_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.OPENED_JAVA_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.OPENED_NODEJS_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.OPENED_PYTHON_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.OPENED_GO_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.CLOSED_CPP_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.CLOSED_CSHARP_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.CLOSED_JAVA_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.CLOSED_NODEJS_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.CLOSED_PYTHON_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.CLOSED_GO_CLIENT_CONNECTIONS_COUNT.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.TOTAL_CPP_CLIENT_CONNECTION_DURATION.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.TOTAL_CSHARP_CLIENT_CONNECTION_DURATION.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.TOTAL_JAVA_CLIENT_CONNECTION_DURATION.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.TOTAL_NODEJS_CLIENT_CONNECTION_DURATION.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.TOTAL_PYTHON_CLIENT_CONNECTION_DURATION.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.TOTAL_GO_CLIENT_CONNECTION_DURATION.getRequestParameterName()), "0");
assertEquals(parameters.get(PhoneHomeMetrics.CPP_CLIENT_VERSIONS.getRequestParameterName()), "");
assertEquals(parameters.get(PhoneHomeMetrics.CSHARP_CLIENT_VERSIONS.getRequestParameterName()), "");
assertEquals(parameters.get(PhoneHomeMetrics.JAVA_CLIENT_VERSIONS.getRequestParameterName()), "");
assertEquals(parameters.get(PhoneHomeMetrics.NODEJS_CLIENT_VERSIONS.getRequestParameterName()), "");
assertEquals(parameters.get(PhoneHomeMetrics.PYTHON_CLIENT_VERSIONS.getRequestParameterName()), "");
assertEquals(parameters.get(PhoneHomeMetrics.GO_CLIENT_VERSIONS.getRequestParameterName()), "");
assertFalse(Integer.parseInt(parameters.get(PhoneHomeMetrics.TIME_TAKEN_TO_CLUSTER_UP.getRequestParameterName())) < 0);
assertNotEquals(parameters.get(PhoneHomeMetrics.UPTIME_OF_RUNTIME_MXBEAN.getRequestParameterName()), "0");
assertNotEquals(parameters.get(PhoneHomeMetrics.UPTIME_OF_RUNTIME_MXBEAN.getRequestParameterName()), parameters.get(PhoneHomeMetrics.TIME_TAKEN_TO_CLUSTER_UP.getRequestParameterName()));
assertEquals(parameters.get(PhoneHomeMetrics.OPERATING_SYSTEM_NAME.getRequestParameterName()), osMxBean.getName());
assertEquals(parameters.get(PhoneHomeMetrics.OPERATING_SYSTEM_ARCH.getRequestParameterName()), osMxBean.getArch());
assertEquals(parameters.get(PhoneHomeMetrics.OPERATING_SYSTEM_VERSION.getRequestParameterName()), osMxBean.getVersion());
assertEquals(parameters.get(PhoneHomeMetrics.RUNTIME_MXBEAN_VM_NAME.getRequestParameterName()), runtimeMxBean.getVmName());
assertEquals(parameters.get(PhoneHomeMetrics.JAVA_VERSION_OF_SYSTEM.getRequestParameterName()), System.getProperty("java.version"));
assertEquals(parameters.get(PhoneHomeMetrics.JET_ENABLED.getRequestParameterName()), "true");
assertEquals(parameters.get(PhoneHomeMetrics.JET_RESOURCE_UPLOAD_ENABLED.getRequestParameterName()), "false");
assertEquals(parameters.get(PhoneHomeMetrics.CP_SUBSYSTEM_ENABLED.getRequestParameterName()), "false");
assertEquals(parameters.get(PhoneHomeMetrics.DYNAMIC_CONFIG_PERSISTENCE_ENABLED.getRequestParameterName()), "false");
}
use of java.lang.management.OperatingSystemMXBean in project dubbo by alibaba.
the class LoadStatusChecker method check.
@Override
public Status check() {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
double load;
try {
Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
if (load == -1) {
com.sun.management.OperatingSystemMXBean bean = (com.sun.management.OperatingSystemMXBean) operatingSystemMXBean;
load = bean.getSystemCpuLoad();
}
} catch (Throwable e) {
load = -1;
}
int cpu = operatingSystemMXBean.getAvailableProcessors();
return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
use of java.lang.management.OperatingSystemMXBean in project gocd by gocd.
the class OSInformationProvider method asJson.
@Override
public Map<String, Object> asJson() {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
LinkedHashMap<String, Object> json = new LinkedHashMap<>();
json.put("OS Name", operatingSystemMXBean.getName());
json.put("OS Version", operatingSystemMXBean.getVersion());
json.put("System Architecture", operatingSystemMXBean.getArch());
json.put("Available Processors", operatingSystemMXBean.getAvailableProcessors());
json.put("Average System Load", operatingSystemMXBean.getSystemLoadAverage());
return json;
}
use of java.lang.management.OperatingSystemMXBean in project jdbc-shards by wplatform.
the class Utils method scaleForAvailableMemory.
/**
* Scale the value with the available memory. If 1 GB of RAM is available,
* the value is returned, if 2 GB are available, then twice the value, and
* so on.
*
* @param value the value to scale
* @return the scaled value
*/
public static int scaleForAvailableMemory(int value) {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory != Long.MAX_VALUE) {
// we are limited by an -XmX parameter
return (int) (value * maxMemory / (1024 * 1024 * 1024));
}
try {
OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
// this method is only available on the class
// com.sun.management.OperatingSystemMXBean, which mxBean
// is an instance of under the Oracle JDK, but it is not present on
// Android and other JDK's
Method method = Class.forName("com.sun.management.OperatingSystemMXBean").getMethod("getTotalPhysicalMemorySize");
long physicalMemorySize = ((Number) method.invoke(mxBean)).longValue();
return (int) (value * physicalMemorySize / (1024 * 1024 * 1024));
} catch (Exception e) {
// ignore
}
return value;
}
Aggregations