use of java.lang.management.OperatingSystemMXBean in project lucene-solr by apache.
the class SystemInfoHandlerTest method testMagickGetter.
public void testMagickGetter() throws Exception {
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
// make one directly
SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
info.add("name", os.getName());
info.add("version", os.getVersion());
info.add("arch", os.getArch());
// make another using MetricUtils.addMXBeanMetrics()
SimpleOrderedMap<Object> info2 = new SimpleOrderedMap<>();
MetricUtils.addMXBeanMetrics(os, OperatingSystemMXBean.class, null, (k, v) -> {
info2.add(k, ((Gauge) v).getValue());
});
// make sure they got the same thing
for (String p : Arrays.asList("name", "version", "arch")) {
assertEquals(info.get(p), info2.get(p));
}
}
use of java.lang.management.OperatingSystemMXBean in project hazelcast by hazelcast.
the class PhoneHome method phoneHome.
public Map<String, String> phoneHome(Node hazelcastNode, String version, boolean isEnterprise) {
String downloadId = "source";
InputStream is = null;
try {
is = getClass().getClassLoader().getResourceAsStream("hazelcast-download.properties");
if (is != null) {
final Properties properties = new Properties();
properties.load(is);
downloadId = properties.getProperty("hazelcastDownloadId");
}
} catch (IOException ignored) {
EmptyStatement.ignore(ignored);
} finally {
IOUtil.closeResource(is);
}
//Calculate native memory usage from native memory config
NativeMemoryConfig memoryConfig = hazelcastNode.getConfig().getNativeMemoryConfig();
final ClusterServiceImpl clusterService = hazelcastNode.getClusterService();
long totalNativeMemorySize = clusterService.getSize(DATA_MEMBER_SELECTOR) * memoryConfig.getSize().bytes();
String nativeMemoryParameter = (isEnterprise) ? Long.toString(MemoryUnit.BYTES.toGigaBytes(totalNativeMemorySize)) : "0";
//Calculate connected clients to the cluster.
Map<ClientType, Integer> clusterClientStats = hazelcastNode.clientEngine.getConnectedClientStats();
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
Long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();
PhoneHomeParameterCreator parameterCreator = new PhoneHomeParameterCreator();
parameterCreator.addParam("version", version);
parameterCreator.addParam("m", hazelcastNode.getThisUuid());
parameterCreator.addParam("e", Boolean.toString(isEnterprise));
parameterCreator.addParam("l", MD5Util.toMD5String(hazelcastNode.getConfig().getLicenseKey()));
parameterCreator.addParam("p", downloadId);
parameterCreator.addParam("c", clusterService.getClusterId());
parameterCreator.addParam("crsz", convertToLetter(clusterService.getMembers().size()));
parameterCreator.addParam("cssz", convertToLetter(hazelcastNode.clientEngine.getClientEndpointCount()));
parameterCreator.addParam("hdgb", nativeMemoryParameter);
parameterCreator.addParam("ccpp", Integer.toString(clusterClientStats.get(ClientType.CPP)));
parameterCreator.addParam("cdn", Integer.toString(clusterClientStats.get(ClientType.CSHARP)));
parameterCreator.addParam("cjv", Integer.toString(clusterClientStats.get(ClientType.JAVA)));
parameterCreator.addParam("cnjs", Integer.toString(clusterClientStats.get(ClientType.NODEJS)));
parameterCreator.addParam("cpy", Integer.toString(clusterClientStats.get(ClientType.PYTHON)));
parameterCreator.addParam("cuptm", Long.toString(clusterUpTime));
parameterCreator.addParam("nuptm", Long.toString(runtimeMxBean.getUptime()));
parameterCreator.addParam("jvmn", runtimeMxBean.getVmName());
parameterCreator.addParam("jvmv", System.getProperty("java.version"));
JetBuildInfo jetBuildInfo = hazelcastNode.getBuildInfo().getJetBuildInfo();
parameterCreator.addParam("jetv", jetBuildInfo == null ? "" : jetBuildInfo.getVersion());
try {
parameterCreator.addParam("osn", osMxBean.getName());
parameterCreator.addParam("osa", osMxBean.getArch());
parameterCreator.addParam("osv", osMxBean.getVersion());
} catch (SecurityException e) {
parameterCreator.addParam("osn", "N/A");
parameterCreator.addParam("osa", "N/A");
parameterCreator.addParam("osv", "N/A");
}
String urlStr = BASE_PHONE_HOME_URL + parameterCreator.build();
fetchWebService(urlStr);
return parameterCreator.getParameters();
}
use of java.lang.management.OperatingSystemMXBean in project hazelcast by hazelcast.
the class OperatingSystemMetricSetTest method assumeOperatingSystemMXBean.
private void assumeOperatingSystemMXBean(String expected) {
OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
String foundClass = bean.getClass().getName();
assumeTrue(foundClass + " is not usable", expected.equals(foundClass));
}
use of java.lang.management.OperatingSystemMXBean in project hazelcast by hazelcast.
the class PhoneHomeTest method testPhoneHomeParameters.
@Test
public void testPhoneHomeParameters() throws Exception {
Node node1 = TestUtil.getNode(hz1);
PhoneHome phoneHome = new PhoneHome();
sleepAtLeastMillis(1);
Map<String, String> parameters = phoneHome.phoneHome(node1, "test_version", false);
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
assertEquals(parameters.get("version"), "test_version");
assertEquals(parameters.get("m"), node1.getLocalMember().getUuid());
assertEquals(parameters.get("e"), "false");
assertEquals(parameters.get("l"), "NULL");
assertEquals(parameters.get("p"), "source");
assertEquals(parameters.get("crsz"), "A");
assertEquals(parameters.get("cssz"), "A");
assertEquals(parameters.get("hdgb"), "0");
assertEquals(parameters.get("ccpp"), "0");
assertEquals(parameters.get("cdn"), "0");
assertEquals(parameters.get("cjv"), "0");
assertEquals(parameters.get("cnjs"), "0");
assertEquals(parameters.get("cpy"), "0");
assertEquals(parameters.get("jetv"), "");
assertFalse(Integer.parseInt(parameters.get("cuptm")) < 0);
assertNotEquals(parameters.get("nuptm"), "0");
assertNotEquals(parameters.get("nuptm"), parameters.get("cuptm"));
assertEquals(parameters.get("osn"), osMxBean.getName());
assertEquals(parameters.get("osa"), osMxBean.getArch());
assertEquals(parameters.get("osv"), osMxBean.getVersion());
assertEquals(parameters.get("jvmn"), runtimeMxBean.getVmName());
assertEquals(parameters.get("jvmv"), System.getProperty("java.version"));
}
use of java.lang.management.OperatingSystemMXBean in project pentaho-kettle by pentaho.
the class GetStatusServlet method getSystemInfo.
private static void getSystemInfo(SlaveServerStatus serverStatus) {
OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean();
RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean();
int cores = Runtime.getRuntime().availableProcessors();
long freeMemory = Runtime.getRuntime().freeMemory();
long totalMemory = Runtime.getRuntime().totalMemory();
String osArch = operatingSystemMXBean.getArch();
String osName = operatingSystemMXBean.getName();
String osVersion = operatingSystemMXBean.getVersion();
double loadAvg = operatingSystemMXBean.getSystemLoadAverage();
int threadCount = threadMXBean.getThreadCount();
long allThreadsCpuTime = 0L;
long[] threadIds = threadMXBean.getAllThreadIds();
for (int i = 0; i < threadIds.length; i++) {
allThreadsCpuTime += threadMXBean.getThreadCpuTime(threadIds[i]);
}
long uptime = runtimeMXBean.getUptime();
serverStatus.setCpuCores(cores);
serverStatus.setCpuProcessTime(allThreadsCpuTime);
serverStatus.setUptime(uptime);
serverStatus.setThreadCount(threadCount);
serverStatus.setLoadAvg(loadAvg);
serverStatus.setOsName(osName);
serverStatus.setOsVersion(osVersion);
serverStatus.setOsArchitecture(osArch);
serverStatus.setMemoryFree(freeMemory);
serverStatus.setMemoryTotal(totalMemory);
}
Aggregations