Java获取系统CPU温度和硬盘温度

<dependency>
    <groupId>io.github.pandalxb</groupId>
    <artifactId>jSensors</artifactId>
    <version>1.0.0</version>
</dependency>
package io.github.pandalxb.test;
  
import io.github.pandalxb.jsensors.JSensors;
import io.github.pandalxb.jsensors.model.components.Components;
import io.github.pandalxb.jsensors.model.components.Cpu;
import io.github.pandalxb.jsensors.model.components.Disk;
import io.github.pandalxb.jsensors.model.sensors.Temperature;
  
import java.util.List;
  
public class JSensorsTest {
    public static void main(String[] args) {
        Components components = JSensors.get.components();
  
        List<Cpu> cpus = components.cpus;
        if (cpus != null) {
            for (final Cpu cpu : cpus) {
                System.out.println("Found CPU component: " + cpu.name);
                if (cpu.sensors != null) {
                    System.out.println("Sensors: ");
                    //Print temperatures
                    List<Temperature> temps = cpu.sensors.temperatures;
                    for (final Temperature temp : temps) {
                        System.out.println(temp.name + ": " + temp.value + " C");
                    }
                }
            }
        }
  
        List<Disk> disks = components.disks;
        if (disks != null) {
            for (final Disk disk : disks) {
                System.out.println("Found Disk component: " + disk.name);
                if (disk.sensors != null) {
                    System.out.println("Sensors: ");
                    //Print temperatures
                    List<Temperature> temps = disk.sensors.temperatures;
                    for (final Temperature temp : temps) {
                        System.out.println(temp.name + ": " + temp.value + " C");
                    }
                }
            }
        }
    }
}
Found CPU component: Intel Core i5-4590
Sensors: 
Temp Core Max: 51.0 C
Temp Core Average: 50.0 C
Temp CPU Core #1: 50.0 C
Temp CPU Core #2: 51.0 C
Temp CPU Core #3: 51.0 C
Temp CPU Core #4: 48.0 C
Temp CPU Package: 51.0 C
Temp CPU Core #1 Distance to TjMax: 50.0 C
Temp CPU Core #2 Distance to TjMax: 49.0 C
Temp CPU Core #3 Distance to TjMax: 49.0 C
Temp CPU Core #4 Distance to TjMax: 52.0 C
Found Disk component: SanDisk SSD PLUS 120GB
Sensors: 
Temp Temperature: 26.0 C
Found Disk component: WDC WD10EZEX-08WN4A0
Sensors: 
Temp Temperature: 29.0 C
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值