use of oshi.hardware.HardwareAbstractionLayer 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