oshi.software.os.OperatingSystem Java Examples

The following examples show how to use oshi.software.os.OperatingSystem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerInfo.java    From mogu_blog_v2 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #2
Source File: OshiPlatformCacheTest.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
@Test
public void getOperatingSystemInfo() {
    OshiPlatformCache oshi = newOshiPlatformCache();
    OperatingSystem os = oshi.getOperatingSystem();

    Assert.assertNotNull(os);

    String family = os.getFamily();
    String manu = os.getManufacturer();
    OperatingSystemVersion version = os.getVersion();

    Assert.assertNotNull(family);
    Assert.assertNotNull(manu);
    Assert.assertNotNull(version);

    print("===OPERATION SYSTEM==");
    print("  Family=[%s]", family);
    print("  Manufacturer=[%s]", manu);
    print("  Version=[%s](%s)", version, version.getClass());
    print("  toString=[%s]", os.toString());
}
 
Example #3
Source File: StatsTask.java    From Lavalink with MIT License 6 votes vote down vote up
private double getProcessRecentCpuUsage() {
    double output;
    HardwareAbstractionLayer hal = si.getHardware();
    OperatingSystem os = si.getOperatingSystem();
    OSProcess p = os.getProcess(os.getProcessId());

    if (cpuTime != 0) {
        double uptimeDiff = p.getUpTime() - uptime;
        double cpuDiff = (p.getKernelTime() + p.getUserTime()) - cpuTime;
        output = cpuDiff / uptimeDiff;
    } else {
        output = ((double) (p.getKernelTime() + p.getUserTime())) / (double) p.getUserTime();
    }

    // Record for next invocation
    uptime = p.getUpTime();
    cpuTime = p.getKernelTime() + p.getUserTime();
    return output / hal.getProcessor().getLogicalProcessorCount();
}
 
Example #4
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #5
Source File: SystemHardwareInfo.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFileInfo sysFile = new SysFileInfo();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));

        if (total == 0) {
            sysFile.setUsage(0);
        } else {
            sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        }

        sysFiles.add(sysFile);
    }
}
 
Example #6
Source File: MonitorServiceImpl.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取磁盘信息
 *
 * @return /
 */
private Map<String, Object> getDiskInfo(OperatingSystem os) {
	Map<String, Object> diskInfo = new LinkedHashMap<>();
	try {
		FileSystem fileSystem = os.getFileSystem();
		List<OSFileStore> fsArray = fileSystem.getFileStores();
		for (OSFileStore fs : fsArray) {
			diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtil.getSize(fs.getTotalSpace()) : "?");
			long used = fs.getTotalSpace() - fs.getUsableSpace();
			diskInfo.put("available", FileUtil.getSize(fs.getUsableSpace()));
			diskInfo.put("used", FileUtil.getSize(used));
			diskInfo.put("usageRate", df.format(used / (double) fs.getTotalSpace() * 100));
		}
	} catch (Exception e) {
		log.error("{}", e);
	}
	return diskInfo;
}
 
Example #7
Source File: MonitorServiceImpl.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, Object> getServers() {
	Map<String, Object> resultMap = new LinkedHashMap<>(8);
	try {
		SystemInfo si = new SystemInfo();
		OperatingSystem os = si.getOperatingSystem();
		HardwareAbstractionLayer hal = si.getHardware();
		// 系统信息
		resultMap.put("sys", getSystemInfo(os));
		// cpu 信息
		resultMap.put("cpu", getCpuInfo(hal.getProcessor()));
		// 内存信息
		resultMap.put("memory", getMemoryInfo(hal.getMemory()));
		// 交换区信息
		resultMap.put("swap", getSwapInfo(hal.getMemory()));
		// 磁盘
		resultMap.put("disk", getDiskInfo(os));
		resultMap.put("time", DateUtil.format(new Date(), "HH:mm:ss"));
	} catch (Exception e) {
		e.printStackTrace();
	}
	return resultMap;
}
 
Example #8
Source File: Server.java    From boot-actuator with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #9
Source File: Server.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #10
Source File: Server.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #11
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #12
Source File: Server.java    From Shiro-Action with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #13
Source File: ServerServiceImpl.java    From DimpleBlog with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> getServers() {
    Map<String, Object> resultMap = new LinkedHashMap<>(8);
    try {
        SystemInfo si = new SystemInfo();
        OperatingSystem os = si.getOperatingSystem();
        HardwareAbstractionLayer hal = si.getHardware();
        // 系统信息
        resultMap.put("sys", getSystemInfo(os));
        // cpu 信息
        resultMap.put("cpu", getCpuInfo(hal.getProcessor()));
        // 内存信息
        resultMap.put("memory", getMemoryInfo(hal.getMemory()));
        // 交换区信息
        resultMap.put("swap", getSwapInfo(hal.getMemory()));
        // 磁盘
        resultMap.put("disk", getDiskInfo(os));
        resultMap.put("time", DateUtils.parseDateToStr("HH:mm:ss", new Date()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resultMap;
}
 
Example #14
Source File: Server.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #15
Source File: MonitorServiceImpl.java    From eladmin with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String,Object> getServers(){
    Map<String, Object> resultMap = new LinkedHashMap<>(8);
    try {
        SystemInfo si = new SystemInfo();
        OperatingSystem os = si.getOperatingSystem();
        HardwareAbstractionLayer hal = si.getHardware();
        // 系统信息
        resultMap.put("sys", getSystemInfo(os));
        // cpu 信息
        resultMap.put("cpu", getCpuInfo(hal.getProcessor()));
        // 内存信息
        resultMap.put("memory", getMemoryInfo(hal.getMemory()));
        // 交换区信息
        resultMap.put("swap", getSwapInfo(hal.getMemory()));
        // 磁盘
        resultMap.put("disk", getDiskInfo(os));
        resultMap.put("time", DateUtil.format(new Date(), "HH:mm:ss"));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resultMap;
}
 
Example #16
Source File: Server.java    From LuckyFrameClient with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * ���ô�����Ϣ
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #17
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #18
Source File: Server.java    From RuoYi-Vue with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #19
Source File: Server.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #20
Source File: Server.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #21
Source File: ProcessHelper.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Gets resource consumption of the process with the given pid. */
@Nullable
public ProcessResourceConsumption getProcessResourceConsumption(long pid) {
  try {
    OperatingSystem os = OSHI.getOperatingSystem();
    OSProcess process = os.getProcess((int) pid);
    return getProcessResourceConsumptionInternal(process);
  } catch (Exception ex) {
    // do nothing
    return null;
  }
}
 
Example #22
Source File: ServerServiceImpl.java    From DimpleBlog with Apache License 2.0 5 votes vote down vote up
/**
 * 获取磁盘信息
 *
 * @return /
 */
private Map<String, Object> getDiskInfo(OperatingSystem os) {
    Map<String, Object> diskInfo = new LinkedHashMap<>();
    FileSystem fileSystem = os.getFileSystem();
    List<OSFileStore> fsArray = Arrays.asList(fileSystem.getFileStores());
    for (OSFileStore fs : fsArray) {
        diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtils.getSizeString(fs.getTotalSpace()) : "?");
        long used = fs.getTotalSpace() - fs.getUsableSpace();
        diskInfo.put("available", FileUtils.getSizeString(fs.getUsableSpace()));
        diskInfo.put("used", FileUtils.getSizeString(used));
        diskInfo.put("usageRate", df.format(used / (double) fs.getTotalSpace() * 100));
    }
    return diskInfo;
}
 
Example #23
Source File: NativeCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void displayNativeInfo(CommandSender sender, SystemInfo systemInfo) {
    HardwareAbstractionLayer hardware = systemInfo.getHardware();
    OperatingSystem operatingSystem = systemInfo.getOperatingSystem();

    //swap and load is already available in the environment command because MBeans already supports this
    long uptime = TimeUnit.SECONDS.toMillis(operatingSystem.getSystemUptime());
    String uptimeFormat = LagMonitor.formatDuration(Duration.ofMillis(uptime));
    sendMessage(sender, "OS Uptime", uptimeFormat);

    String startTime = LagMonitor.formatDuration(Duration.ofMillis(uptime));
    sendMessage(sender, "OS Start time", startTime);

    sendMessage(sender, "CPU Freq", Arrays.toString(hardware.getProcessor().getCurrentFreq()));
    sendMessage(sender, "CPU Max Freq", String.valueOf(hardware.getProcessor().getMaxFreq()));
    sendMessage(sender, "VM Hypervisor", DetectVM.identifyVM());

    // //IO wait
    // double wait = cpuPerc.getWait();
    // sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%');
    //
    // Mem mem = sigar.getMem();
    // //included cache
    // long actualUsed = mem.getActualUsed();
    // long used = mem.getUsed();
    //
    // long cache = used - actualUsed;
    // sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache));

    //disk
    printDiskInfo(sender, hardware.getDiskStores());
    displayMounts(sender, operatingSystem.getFileSystem().getFileStores());

    printSensorsInfo(sender, hardware.getSensors());
    printBoardInfo(sender, hardware.getComputerSystem());

    printRAMInfo(sender, hardware.getMemory().getPhysicalMemory());
}
 
Example #24
Source File: NativeCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void displayNativeInfo(CommandSender sender, SystemInfo systemInfo) {
    HardwareAbstractionLayer hardware = systemInfo.getHardware();
    OperatingSystem operatingSystem = systemInfo.getOperatingSystem();

    //swap and load is already available in the environment command because MBeans already supports this
    long uptime = TimeUnit.SECONDS.toMillis(operatingSystem.getSystemUptime());
    String uptimeFormat = LagMonitor.formatDuration(Duration.ofMillis(uptime));
    sendMessage(sender, "OS Uptime", uptimeFormat);

    String startTime = LagMonitor.formatDuration(Duration.ofMillis(uptime));
    sendMessage(sender, "OS Start time", startTime);

    sendMessage(sender, "CPU Freq", Arrays.toString(hardware.getProcessor().getCurrentFreq()));
    sendMessage(sender, "CPU Max Freq", String.valueOf(hardware.getProcessor().getMaxFreq()));
    sendMessage(sender, "VM Hypervisor", DetectVM.identifyVM());

    // //IO wait
    // double wait = cpuPerc.getWait();
    // sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%');
    //
    // Mem mem = sigar.getMem();
    // //included cache
    // long actualUsed = mem.getActualUsed();
    // long used = mem.getUsed();
    //
    // long cache = used - actualUsed;
    // sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache));

    //disk
    printDiskInfo(sender, hardware.getDiskStores());
    displayMounts(sender, operatingSystem.getFileSystem().getFileStores());

    printSensorsInfo(sender, hardware.getSensors());
    printBoardInfo(sender, hardware.getComputerSystem());

    printRAMInfo(sender, hardware.getMemory().getPhysicalMemory());
}
 
Example #25
Source File: MonitorServiceImpl.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取系统相关信息,系统、运行天数、系统IP
 *
 * @param os /
 * @return /
 */
private Map<String, Object> getSystemInfo(OperatingSystem os) {
	Map<String, Object> systemInfo = new LinkedHashMap<>();
	// jvm 运行时间
	long time = ManagementFactory.getRuntimeMXBean().getStartTime();
	Date date = new Date(time);
	// 计算项目运行时间
	String formatBetween = DateUtil.formatBetween(date, new Date(), BetweenFormater.Level.HOUR);
	// 系统信息
	systemInfo.put("os", os.toString());
	systemInfo.put("day", formatBetween);
	systemInfo.put("ip", WebUtil.getHostIp());
	return systemInfo;
}
 
Example #26
Source File: UsageStatisticsCollectorImpl.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
private void collectSystemStatistics(final @NotNull Statistic statistic) {

        if (!SYSTEM_METRICS_ENABLED) {
            return;
        }

        final OperatingSystem operatingSystem;
        final HardwareAbstractionLayer hardware;
        try {
            final SystemInfo systemInfo = new SystemInfo();
            operatingSystem = systemInfo.getOperatingSystem();
            hardware = systemInfo.getHardware();
        } catch (final UnsupportedOperationException e) {
            log.debug("system metrics are not supported, ignoring extended system information");
            log.trace("original exception", e);
            return;
        }

        statistic.setOsManufacturer(operatingSystem.getManufacturer());
        statistic.setOs(operatingSystem.getFamily());
        final OperatingSystemVersion version = operatingSystem.getVersion();
        statistic.setOsVersion(version.getVersion());
        statistic.setOpenFileLimit(operatingSystem.getFileSystem().getMaxFileDescriptors());

        //disk space in MB
        long totalDiskSpace = 0;
        for (final OSFileStore osFileStore : operatingSystem.getFileSystem().getFileStores()) {
            totalDiskSpace += (osFileStore.getTotalSpace() / 1024 / 1024);
        }
        statistic.setDiskSize(totalDiskSpace);

        final CentralProcessor processor = hardware.getProcessor();
        statistic.setCpu(processor.toString());
        statistic.setCpuSockets(processor.getPhysicalPackageCount());
        statistic.setCpuPhysicalCores(processor.getPhysicalProcessorCount());
        statistic.setCpuTotalCores(processor.getLogicalProcessorCount());

        statistic.setOsUptime(processor.getSystemUptime());
        statistic.setMemorySize(hardware.getMemory().getTotal() / 1024 / 1024);
    }
 
Example #27
Source File: MonitorServiceImpl.java    From eladmin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取磁盘信息
 * @return /
 */
private Map<String,Object> getDiskInfo(OperatingSystem os) {
    Map<String,Object> diskInfo = new LinkedHashMap<>();
    FileSystem fileSystem = os.getFileSystem();
    List<OSFileStore> fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray){
        diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtil.getSize(fs.getTotalSpace()) : "?");
        long used = fs.getTotalSpace() - fs.getUsableSpace();
        diskInfo.put("available", FileUtil.getSize(fs.getUsableSpace()));
        diskInfo.put("used", FileUtil.getSize(used));
        diskInfo.put("usageRate", df.format(used/(double)fs.getTotalSpace() * 100));
    }
    return diskInfo;
}
 
Example #28
Source File: MonitorServiceImpl.java    From eladmin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取系统相关信息,系统、运行天数、系统IP
 * @param os /
 * @return /
 */
private Map<String,Object> getSystemInfo(OperatingSystem os){
    Map<String,Object> systemInfo = new LinkedHashMap<>();
    // jvm 运行时间
    long time = ManagementFactory.getRuntimeMXBean().getStartTime();
    Date date = new Date(time);
    // 计算项目运行时间
    String formatBetween = DateUtil.formatBetween(date, new Date(),BetweenFormater.Level.HOUR);
    // 系统信息
    systemInfo.put("os", os.toString());
    systemInfo.put("day", formatBetween);
    systemInfo.put("ip", StringUtils.getLocalIp());
    return systemInfo;
}
 
Example #29
Source File: ServerServiceImpl.java    From DimpleBlog with Apache License 2.0 5 votes vote down vote up
/**
 * 获取系统相关信息,系统、运行天数、系统IP
 *
 * @param os /
 * @return /
 */
private Map<String, Object> getSystemInfo(OperatingSystem os) {
    Map<String, Object> systemInfo = new LinkedHashMap<>();
    // 计算项目运行时间
    String formatBetween = DateUtils.getDatePoor(DateUtils.getServerStartDate(), new Date());
    // 系统信息
    systemInfo.put("os", os.toString());
    systemInfo.put("day", formatBetween);
    systemInfo.put("ip", IpUtils.getHostIp());
    return systemInfo;
}
 
Example #30
Source File: EnvironmentCommand.java    From LagMonitor with MIT License 4 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();

    //os general info
    sendMessage(sender, "OS Name", osBean.getName());
    sendMessage(sender, "OS Arch", osBean.getArch());

    Optional<SystemInfo> optInfo = plugin.getNativeData().getSystemInfo();
    if (optInfo.isPresent()) {
        SystemInfo systemInfo = optInfo.get();

        OperatingSystem osInfo = systemInfo.getOperatingSystem();
        sendMessage(sender, "OS family", osInfo.getFamily());
        sendMessage(sender, "OS version", osInfo.getVersionInfo().toString());
        sendMessage(sender, "OS Manufacturer", osInfo.getManufacturer());

        sendMessage(sender, "Total processes", String.valueOf(osInfo.getProcessCount()));
        sendMessage(sender, "Total threads", String.valueOf(osInfo.getThreadCount()));
    }

    //CPU
    sender.sendMessage(PRIMARY_COLOR + "CPU:");
    if (optInfo.isPresent()) {
        CentralProcessor processor = optInfo.get().getHardware().getProcessor();
        ProcessorIdentifier identifier = processor.getProcessorIdentifier();

        sendMessage(sender, "    Vendor", identifier.getVendor());
        sendMessage(sender, "    Family", identifier.getFamily());
        sendMessage(sender, "    Name", identifier.getName());
        sendMessage(sender, "    Model", identifier.getModel());
        sendMessage(sender, "    Id", identifier.getIdentifier());
        sendMessage(sender, "    Vendor freq", String.valueOf(identifier.getVendorFreq()));
        sendMessage(sender, "    Physical Cores", String.valueOf(processor.getPhysicalProcessorCount()));
    }

    sendMessage(sender, "    Logical Cores", String.valueOf(osBean.getAvailableProcessors()));
    sendMessage(sender, "    Endian", System.getProperty("sun.cpu.endian", "Unknown"));

    sendMessage(sender, "Load Average", String.valueOf(osBean.getSystemLoadAverage()));
    printExtendOsInfo(sender);

    displayDiskSpace(sender);

    NativeManager nativeData = plugin.getNativeData();
    sendMessage(sender, "Open file descriptors", String.valueOf(nativeData.getOpenFileDescriptors()));
    sendMessage(sender, "Max file descriptors", String.valueOf(nativeData.getMaxFileDescriptors()));

    sender.sendMessage(PRIMARY_COLOR + "Variables:");
    for (Entry<String, String> variable : System.getenv().entrySet()) {
        sendMessage(sender, "    " + variable.getKey(), variable.getValue());
    }

    return true;
}