use of java.lang.management.OperatingSystemMXBean in project openj9 by eclipse.
the class TestManagementFactory method testGetOperatingSystemMXBean.
@Test
public final void testGetOperatingSystemMXBean() {
OperatingSystemMXBean ob1 = ManagementFactory.getOperatingSystemMXBean();
AssertJUnit.assertNotNull(ob1);
// Verify that there is only instance of the this bean
OperatingSystemMXBean ob2 = ManagementFactory.getOperatingSystemMXBean();
AssertJUnit.assertNotNull(ob2);
AssertJUnit.assertSame(ob1, ob2);
}
use of java.lang.management.OperatingSystemMXBean in project openj9 by eclipse.
the class TestManagementFactory method testOperatingSystemMXBeanProxy.
@Test
public void testOperatingSystemMXBeanProxy() {
try {
OperatingSystemMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=OperatingSystem", OperatingSystemMXBean.class);
AssertJUnit.assertNotNull(proxy);
AssertJUnit.assertNotNull(proxy.toString());
AssertJUnit.assertEquals("java.lang:type=OperatingSystem", proxy.getObjectName().toString());
AssertJUnit.assertEquals(proxy.getArch(), ManagementFactory.getOperatingSystemMXBean().getArch());
AssertJUnit.assertEquals(proxy.getName(), ManagementFactory.getOperatingSystemMXBean().getName());
AssertJUnit.assertEquals(proxy.getVersion(), ManagementFactory.getOperatingSystemMXBean().getVersion());
AssertJUnit.assertEquals(proxy.getAvailableProcessors(), ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors());
} catch (IOException e) {
Assert.fail("Unexpected IOException : " + e.getMessage());
e.printStackTrace();
}
}
use of java.lang.management.OperatingSystemMXBean in project rocketmq by apache.
the class StoreUtil method getTotalPhysicalMemorySize.
@SuppressWarnings("restriction")
public static long getTotalPhysicalMemorySize() {
long physicalTotal = 1024 * 1024 * 1024 * 24L;
OperatingSystemMXBean osmxb = ManagementFactory.getOperatingSystemMXBean();
if (osmxb instanceof com.sun.management.OperatingSystemMXBean) {
physicalTotal = ((com.sun.management.OperatingSystemMXBean) osmxb).getTotalPhysicalMemorySize();
}
return physicalTotal;
}
use of java.lang.management.OperatingSystemMXBean in project openolat by klemens.
the class SystemWebService method getEnvironnementXml.
/**
* Return some informations about the environment.
* @response.representation.200.qname {http://www.example.com}environmentVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc A short summary of the number of classes
* @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_ENVVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param request The HTTP request
* @return The informations about the environment
*/
@GET
@Path("environment")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getEnvironnementXml(@Context HttpServletRequest request) {
if (!isAdminOrSystem(request)) {
return null;
}
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
EnvironmentInformationsVO vo = new EnvironmentInformationsVO(os, runtime);
return Response.ok(vo).build();
}
use of java.lang.management.OperatingSystemMXBean in project vertigo by KleeGroup.
the class SystemMetricsProvider method getSystemMetrics.
@Metrics
public List<Metric> getSystemMetrics() {
final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
final Runtime runtime = Runtime.getRuntime();
// ---
final Metric memoryUsed = buildMetric("memoryUsed", () -> Long.valueOf(runtime.totalMemory() / 1024 / 1024).doubleValue());
final Metric memoryUsedPercent = buildMetric("memoryUsedPercent", () -> Long.valueOf(runtime.totalMemory()).doubleValue() / runtime.maxMemory() * 100);
final Metric cpuUsage = buildMetric("cpuUsage", () -> operatingSystemMXBean.getSystemLoadAverage());
// ---
return Arrays.asList(memoryUsed, memoryUsedPercent, cpuUsage);
}
Aggregations