use of java.lang.management.OperatingSystemMXBean in project activemq-artemis by apache.
the class DeadLetterAddressTest method testLargeMessageFileLeak.
@Test
public void testLargeMessageFileLeak() throws Exception {
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
// only run this on *nix systems which will have the com.sun.management.UnixOperatingSystemMXBean (needed to check open file count)
Assume.assumeTrue(os instanceof UnixOperatingSystemMXBean);
long fdBaseline = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount();
final int SIZE = 2 * 1024;
SimpleString dla = new SimpleString("DLA");
SimpleString qName = new SimpleString("q1");
SimpleString adName = new SimpleString("ad1");
AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
SimpleString dlq = new SimpleString("DLQ1");
clientSession.createQueue(dla, dlq, null, false);
clientSession.createQueue(adName, qName, null, false);
for (int i = 0; i < 10; i++) {
ClientProducer producer = clientSession.createProducer(adName);
ClientMessage clientFile = clientSession.createMessage(true);
clientFile.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(SIZE));
producer.send(clientFile);
clientSession.start();
ClientConsumer clientConsumer = clientSession.createConsumer(qName);
ClientMessage m = clientConsumer.receive(500);
m.acknowledge();
Assert.assertNotNull(m);
// force a cancel
clientSession.rollback();
m = clientConsumer.receiveImmediate();
Assert.assertNull(m);
clientConsumer.close();
}
assertTrue("File descriptors are leaking", ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount() - fdBaseline <= 0);
}
use of java.lang.management.OperatingSystemMXBean in project OpenOLAT by OpenOLAT.
the class RuntimeWebService method getSystemSummaryVO.
/**
* Return the statistics about runtime: uptime, classes loaded, memory
* summary, threads count...
*
* @response.representation.200.qname {http://www.example.com}runtimeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The version of the instance
* @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_RUNTIMEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param request The HTTP request
* @return The informations about runtime, uptime, classes loaded, memory summary...
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSystemSummaryVO() {
RuntimeStatisticsVO stats = new RuntimeStatisticsVO();
stats.setMemory(getMemoryStatisticsVO());
stats.setThreads(getThreadStatisticsVO());
stats.setClasses(getClasseStatisticsVO());
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
stats.setSystemLoadAverage(os.getSystemLoadAverage());
stats.setStartTime(new Date(runtime.getStartTime()));
stats.setUpTime(runtime.getUptime());
return Response.ok(stats).build();
}
use of java.lang.management.OperatingSystemMXBean in project OpenOLAT by OpenOLAT.
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 ffx by mjschnie.
the class Resources method logResources.
public static void logResources() {
if (logger.isLoggable(Level.INFO)) {
StringBuilder sb = new StringBuilder();
Runtime runtime = Runtime.getRuntime();
runtime.runFinalization();
runtime.gc();
long MB = 1024 * 1024;
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
if (os instanceof UnixOperatingSystemMXBean) {
UnixOperatingSystemMXBean unixOS = (UnixOperatingSystemMXBean) os;
// CPU Time and Average System Load.
Long time = unixOS.getProcessCpuTime();
sb.append(format("\n Total CPU time: %6.2f (sec)", time * 1.0e-9));
double systemLoadAve = unixOS.getSystemLoadAverage();
if (systemLoadAve >= 0) {
sb.append(format("\n System load average: %6.2f", systemLoadAve));
}
// File handle use.
long open = unixOS.getOpenFileDescriptorCount();
long allowed = unixOS.getMaxFileDescriptorCount();
sb.append(format("\n Open file handles: %6d of %6d allowed", open, allowed));
// System Memory.
long freePhysical = unixOS.getFreePhysicalMemorySize() / MB;
long totalPhysical = unixOS.getTotalPhysicalMemorySize() / MB;
long freeSwap = unixOS.getFreeSwapSpaceSize() / MB;
long totalSwap = unixOS.getTotalSwapSpaceSize() / MB;
sb.append(format("\n System memory: %6d MB free out of %6d MB", freePhysical, totalPhysical));
sb.append(format("\n System swap space: %6d MB free out of %6d MB", freeSwap, totalSwap));
// Log CPU usage.
// double sysCPULoad = unixOS.getSystemCpuLoad() * 100.0;
// double procCPULoad = unixOS.getProcessCpuLoad() * 100.0;
/**
* if (procCPULoad >= 0) { sb.append(format("\n JVM CPU load:
* %6.3f%%", procCPULoad)); } if (sysCPULoad >= 0) {
* sb.append(format("\n System CPU load: %6.3f%%", sysCPULoad));
* }
*/
}
// JVM Memory.
sb.append(format("\n JVM memory: %6d MB free out of %6d MB\n", runtime.freeMemory() / MB, runtime.totalMemory() / MB));
logger.info(sb.toString());
}
}
use of java.lang.management.OperatingSystemMXBean in project syncope by apache.
the class SyncopeLogic method initSystemInfo.
private void initSystemInfo() {
if (SYSTEM_INFO == null) {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
SYSTEM_INFO = new SystemInfo();
try {
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());
}
}
Aggregations