package com.docus.server;

import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.GlobalMemory;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.NetworkIF;
import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

import java.util.Arrays;
import java.util.List;

public class Example {
    public static void main(String[] args) {
        SystemInfo systemInfo = new SystemInfo();
        CentralProcessor processor = systemInfo.getHardware().getProcessor();
        int logicalProcessorCount = processor.getLogicalProcessorCount();
        String cpuModel = processor.getProcessorIdentifier().getName();
        long[] systemCpuLoadTicks = processor.getSystemCpuLoadTicks();

        System.out.println(logicalProcessorCount);
        System.out.println(cpuModel);
        System.out.println(Arrays.asList(systemCpuLoadTicks));

        GlobalMemory memory = systemInfo.getHardware().getMemory();
        long totalMemorySize = memory.getTotal();
        long availableMemorySize = memory.getAvailable();
        double memoryUsage = (totalMemorySize - availableMemorySize) * 100.0 / totalMemorySize;
        System.out.println(totalMemorySize);
        System.out.println(availableMemorySize);
        System.out.println(memoryUsage);

        HardwareAbstractionLayer hal = systemInfo.getHardware();
        FileSystem fileSystem = systemInfo.getOperatingSystem().getFileSystem();
        List<OSFileStore> fileStores = fileSystem.getFileStores();
        for (OSFileStore store : fileStores) {
            long totalSpace = store.getTotalSpace();
            long usableSpace = store.getUsableSpace();
            double usage = (totalSpace - usableSpace) * 100.0 / totalSpace;
            System.out.println(totalSpace);
            System.out.println(usableSpace);
            System.out.println(usage);
        }

        List<NetworkIF> networkIFs = systemInfo.getHardware().getNetworkIFs();
        for (NetworkIF networkIF : networkIFs) {
            String name = networkIF.getName();
            long receiveBytes = networkIF.getBytesRecv();
            long transmitBytes = networkIF.getBytesSent();
            System.out.println(name);
            System.out.println(receiveBytes);
            System.out.println(transmitBytes);
        }
    }
}
