Skip to main content

ds 监控机器资源

看各种开源组件,总能发现一些之前没了解过的角落的工程实践, 不用自己一个个摸索或是从头开发. 比如调度系统需要监控各种执行机的cpu/内存资源用于判断任务分配, 就发现原来有oshi这种开源库可以获取机器信息.

oshi 可以监控主流系统, 包括linux/macos/windows/android.

https://github.com/oshi/oshi

OSHI is a free JNA-based (native) Operating System and Hardware Information library for Java. It does not require the installation of any additional native libraries and aims to provide a cross-platform implementation to retrieve system information, such as OS version, processes, memory and CPU usage, disks and partitions, devices, sensors, etc.

SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
CentralProcessor cpu = hal.getProcessor();