use of oshi.hardware.GlobalMemory in project UniversalMediaServer by UniversalMediaServer.
the class SystemInformation method getSystemInfo.
/**
* Collects and returns system information.
*
* @return A {@link List} of {@link String}s containing the collected system
* information.
*/
public static List<String> getSystemInfo() {
List<String> result = new ArrayList<>();
StringBuilder sb = new StringBuilder();
long jvmMemory = Runtime.getRuntime().maxMemory();
OperatingSystem os = null;
CentralProcessor processor = null;
GlobalMemory memory = null;
try {
SystemInfo systemInfo = new SystemInfo();
HardwareAbstractionLayer hardware = systemInfo.getHardware();
os = systemInfo.getOperatingSystem();
processor = hardware.getProcessor();
memory = hardware.getMemory();
} catch (Error e) {
LOGGER.debug("Could not retrieve system information: {}", e.getMessage());
LOGGER.trace("", e);
}
sb.append("JVM: ").append(System.getProperty("java.vm.name")).append(" ").append(System.getProperty("java.version")).append(" (").append(System.getProperty("sun.arch.data.model")).append("-bit) by ").append(System.getProperty("java.vendor"));
result.add(sb.toString());
sb.setLength(0);
sb.append("OS: ");
if (os != null && isNotBlank(os.toString())) {
sb.append(os.toString()).append(" ").append(getOSBitness()).append("-bit");
} else {
sb.append(System.getProperty("os.name")).append(" ").append(getOSBitness()).append("-bit ");
sb.append(System.getProperty("os.version"));
}
result.add(sb.toString());
sb.setLength(0);
if (processor != null) {
sb.append("CPU: ").append(processor.getName()).append(" with ").append(processor.getPhysicalProcessorCount());
if (processor.getPhysicalProcessorCount() > 1) {
sb.append(" cores");
} else {
sb.append(" core");
}
if (processor.getLogicalProcessorCount() != processor.getPhysicalProcessorCount()) {
sb.append(" (").append(processor.getLogicalProcessorCount());
if (processor.getLogicalProcessorCount() > 1) {
sb.append(" virtual cores)");
} else {
sb.append(" virtual core)");
}
}
result.add(sb.toString());
sb.setLength(0);
}
if (memory != null) {
sb.append("Physical Memory: ").append(StringUtil.formatBytes(memory.getTotal(), true));
result.add(sb.toString());
sb.setLength(0);
sb.append("Free Memory: ").append(StringUtil.formatBytes(memory.getAvailable(), true));
result.add(sb.toString());
sb.setLength(0);
}
sb.append("Maximum JVM Memory: ");
if (jvmMemory == Long.MAX_VALUE) {
sb.append("Unlimited");
} else {
sb.append(StringUtil.formatBytes(jvmMemory, true));
}
result.add(sb.toString());
return result;
}
use of oshi.hardware.GlobalMemory in project graylog2-server by Graylog2.
the class OshiOsProbe method osStats.
@Override
public OsStats osStats() {
final HardwareAbstractionLayer hardware = service.getHal();
final GlobalMemory globalMemory = hardware.getMemory();
final Memory mem = Memory.create(globalMemory.getTotal(), globalMemory.getAvailable(), (short) (globalMemory.getAvailable() * 100 / globalMemory.getTotal()), globalMemory.getTotal() - globalMemory.getAvailable(), (short) ((globalMemory.getTotal() - globalMemory.getAvailable()) * 100 / globalMemory.getTotal()), globalMemory.getAvailable(), globalMemory.getTotal() - globalMemory.getAvailable());
final VirtualMemory virtualMemory = globalMemory.getVirtualMemory();
final Swap swap = Swap.create(virtualMemory.getSwapTotal(), virtualMemory.getSwapTotal() - virtualMemory.getSwapUsed(), virtualMemory.getSwapUsed());
final CentralProcessor centralProcessor = hardware.getProcessor();
long[] prevTicks = centralProcessor.getSystemCpuLoadTicks();
long[] ticks = centralProcessor.getSystemCpuLoadTicks();
short user = (short) (ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()]);
short sys = (short) (ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()]);
short idle = (short) (ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()]);
short steal = (short) (ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()]);
final CentralProcessor.ProcessorIdentifier processorIdentifier = centralProcessor.getProcessorIdentifier();
final Processor proc = Processor.create(processorIdentifier.getName(), processorIdentifier.getVendor(), ((int) processorIdentifier.getVendorFreq() / 1000000), centralProcessor.getLogicalProcessorCount(), centralProcessor.getPhysicalPackageCount(), centralProcessor.getLogicalProcessorCount() / centralProcessor.getPhysicalPackageCount(), -1, sys, user, idle, steal);
return OsStats.create(centralProcessor.getSystemLoadAverage(3), service.getOs().getSystemUptime(), proc, mem, swap);
}
Aggregations