Search in sources :

Example 1 with VirtualMemory

use of oshi.hardware.VirtualMemory in project yyl_example by Relucent.

the class OshiExample method infoMemory.

private static void infoMemory(GlobalMemory memory) {
    println("Memory");
    long total = memory.getTotal();
    long free = memory.getAvailable();
    long used = total - free;
    // 内存总量
    println("  total:        " + total);
    // 已用内存
    println("  used:         " + used);
    // 剩余内存
    println("  free:    " + free);
    VirtualMemory virtualMemory = memory.getVirtualMemory();
    long swapTotal = virtualMemory.getSwapTotal();
    long swapUsed = virtualMemory.getSwapUsed();
    long swapFree = swapTotal - swapUsed;
    println("  swapTotal:   " + swapTotal);
    println("  swapUsed:    " + swapUsed);
    println("  swapFree:    " + swapFree);
}
Also used : VirtualMemory(oshi.hardware.VirtualMemory)

Example 2 with VirtualMemory

use of oshi.hardware.VirtualMemory 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);
}
Also used : HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) GlobalMemory(oshi.hardware.GlobalMemory) CentralProcessor(oshi.hardware.CentralProcessor) GlobalMemory(oshi.hardware.GlobalMemory) VirtualMemory(oshi.hardware.VirtualMemory) CentralProcessor(oshi.hardware.CentralProcessor) VirtualMemory(oshi.hardware.VirtualMemory)

Aggregations

VirtualMemory (oshi.hardware.VirtualMemory)2 CentralProcessor (oshi.hardware.CentralProcessor)1 GlobalMemory (oshi.hardware.GlobalMemory)1 HardwareAbstractionLayer (oshi.hardware.HardwareAbstractionLayer)1