# hw
**Repository Path**: eternalnight996/hw
## Basic Information
- **Project Name**: hw
- **Description**: 一个强大的跨平台硬件监控工具(集成多种(HOM AIDA64 SYSINFO)硬件监控后端,提供统一的命令行接口)
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 0
- **Created**: 2024-12-06
- **Last Updated**: 2025-04-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: HW, hardware, monitor, Monitoring, sysinfo
## README
[](https://github.com/eternalnight996/hw)[](https://docs.rs/hw)[](LICENSE)
[English](readme.md) | 简体中文
## ✨ 特性一览
- 🔄 **多后端集成** - 支持 OpenHardwareMonitor、AIDA64、sysinfo 等多种监控方案
- 🌍 **跨平台支持** - 完整支持 Windows,基础支持 Linux/MacOS
- 📊 **丰富的监控指标** - CPU、GPU、内存、硬盘、主板等全方位监控
- ⚡ **实时数据采集** - 毫秒级的硬件状态监控
- 🔌 **统一接口** - 简洁的命令行工具与 Rust API
- 🛠 **可扩展架构** - 轻松扩展新的监控后端
- 📈 **性能优化** - 低资源占用,高效数据处理
## 🚀 快速开始
### 通过 Cargo 安装
```bash
cargo install hw
```
### 从源码构建
```bash
git clone https://github.com/eternalnight996/hw.git
cd hw
cargo install just
just
```
**命令区别说明:**
- **data**: 仅返回传感器当前值
- **print**: 返回完整统计信息,但不做验证
- **check**: 进行值范围验证和负载测试
- `10`: 测试次数
- `2000`: 目标值
- `3000`: 误差范围 (-1000~5000)
- `100`: CPU负载百分比
---
### 📖 特性
```toml
[dependencies]
# 所有特性
hw = {version="0.1"}
# 打包所有特性
hw = {version="0.1",feature=["build","built"]}
# 只用OHM
hw = {version="0.1", default-features = false, feature=["ohm"]}
# 命令行则加上cli
# 日志 支持 log 和 tracing, cli则默认支持println输出
hw = {version="0.1", default-features = false, feature=["ohm","cli","log"]}
```
---
## 📸 界面预览与命令示例
### [1. 📖 点击Rust调用CLI](examples/cli.rs)
### [2. 📖 点击Rust调用OHM 获取CPU主频](examples/ohm_cpu_clock.rs)
### OpenHardwareMonitor 监控

**CPU Clock监控示例**
1. **data命令** - 仅返回当前值
```bash
hw --api OS --task data --args CPU Clock
```
```rust
Compiling hw v0.1.2 (D:\MyApp\hw)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.18s
Running `target\x86_64-pc-windows-msvc\debug\hw.exe --api OHM --task data --args CPU Clock`
Started OpenHardwareMonitor.exe with PID: 5332
Loading... (100%/100%)
...
--------------------------------
平均值(1068MHz 0.0%) 数据:1068
关闭负载
=== 总结 -> CPU 中央处理器 ===
--- 传感器 -> Clock 频率 MHz ---
结果: PASS
数据: 1068
目标: 0.0 MHz
平均: 1068.0 MHz
最低: 901.2 MHz
最高: 1101.5 MHz
次数: 1
错误次数: 0
负载: 0.0%
平均负载: 0.0%
允许误差: ±0.0
允许范围: 0.0 ~ 0.0 MHz
====================
R<{"content":"1068","status":true,"opts":null}>R
```
2. **print命令** - 返回完整统计信息
```bash
hw --api OHM --task print --full --args CPU Clock
```
```rust
...
R<{"content":"{\"api\":\"OHM\",\"hw_type\":\"CPU\",\"sensor_type\":\"Clock\",\"res\":\"PASS\",\"data\":\"1102\",\"min\":1101.5174560546875,\"max\":1101.5174560546875,\"avg\":1102.0,\"total\":6609.104736328125,\"samples\":6,\"test_secs\":0,\"error_count\":0,\"load\":{\"min\":0.0,\"max\":0.0,\"avg\":0.0,\"total\":0.0,\"status\":[]},\"status\":[...]}","status":true,"opts":null}>R
```
3. **check命令** - 进行值范围验证和负载测试
```bash
hw --api OHM --task check --full --args CPU Clock -- 10 2000 3000 100
```
```rust
...
--- 第 10 秒中央处理器状态 ---
CPU Core #1 - 当前=2904.0 MHz(频率) 误差: ±3000.0
CPU Core #6 - 当前=2904.0 MHz(频率) 误差: ±3000.0
CPU Core #5 - 当前=2904.0 MHz(频率) 误差: ±3000.0
CPU Core #4 - 当前=2904.0 MHz(频率) 误差: ±3000.0
CPU Core #3 - 当前=2904.0 MHz(频率) 误差: ±3000.0
CPU Core #2 - 当前=2904.0 MHz(频率) 误差: ±3000.0
--------------------------------
平均值(2904MHz 99.0%) 数据:2904
关闭负载
=== 总结 -> CPU 中央处理器 ===
--- 传感器 -> Clock 频率 MHz ---
结果: PASS
数据: 2904
目标: 2000.0 MHz
平均: 2904.0 MHz
最低: 2904.0 MHz
最高: 2904.0 MHz
次数: 10
错误次数: 0
负载: 100.0%
平均负载: 99.0%
允许误差: ±3000.0
允许范围: -1000.0 ~ 5000.0 MHz
====================
R<{"content":"{\"api\":\"OHM\",\"hw_type\":\"CPU\",\"sensor_type\":\"Clock\",\"res\":\"PASS\",\"data\":\"2904\",\"min\":2904.000732421875,\"max\":2904.001708984375,\"avg\":2904.0,\"total\":174240.07470703125,\"samples\":60,\"test_secs\":0,\"error_count\":0,\"load\":{\"min\":0.0,\"max\":0.0,\"avg\":99.0,\"total\":5946.0,\"status\":[]},\"status\":[...]}","status":true,"opts":null}>R
```
```bash
# CPU温度监控
hw --api OHM --task check --args CPU Temperature
# CPU频率测试 (5次, 目标3000MHz, 误差±2000MHz, 100%负载)
hw --api OHM --task check --args CPU Clock -- 5 3000 2000 100
# 风扇转速测试 (5次, 目标3000RPM, 误差±2000RPM)
hw --api OHM --task check --args ALL Fan -- 5 3000 2000
```
### [3.📖 点击Rust调用OS 获取CPU主频](examples/os_cpu_clock.rs)
### sysinfo 监控

```bash
# 系统整体状态
hw --api OS --task print
# CPU负载监控
hw --api OS --task check --args CPU Load
```
### [4.📖 点击Rust调用AIDA64 获取CPU主频](examples/aida64_cpu_voltage.rs)
### AIDA64 监控

```bash
# 内存使用率监控
hw --api AIDA64 --task check --args RAM Load
# CPU核心电压监控
hw --api AIDA64 --task check --args CPU Voltage
```
### [X.📖 Click for Rust CoreTemp CPU Voltage Usage](examples/core_temp.rs)
### CoreTemp Monitoring

```bash
# Memory Usage Monitoring
hw --api CoreTemp --task check --args CPU Temperature
# CPU Core Voltage Monitoring
hw --api CoreTemp --task check --args CPU Clock
```
### [X.📖 Click for Rust LibreHardwareMonitor CPU Voltage Usage](examples/lhm_cpu_clock.rs)
```bash
# CPU温度监控
hw --api LHM --task check --args CPU Temperature
# CPU频率测试 (5次, 目标3000MHz, 误差±2000MHz, 100%负载)
hw --api LHM --task check --args CPU Clock -- 5 3000 2000 100
# 风扇转速测试 (5次, 目标3000RPM, 误差±2000RPM)
hw --api LHM --task check --args ALL Fan -- 5 3000 2000
```
### [5. 📖 点击Rust调用OSMore](examples/os_more_base.rs)
```bash
# 获取系统完整信息
hw --api OSMore --task OsFullVersion
# 获取内存大小
hw --api OSMore --task MemoryTotal
# 获取计算机名
hw --api OSMore --task HostName
# 获取OS版本
hw --api OSMore --task OsVersion
```
### [6. 📖 点击Rust调用微软OFFICE](examples/os_office.rs)
```bash
# 获取Office版本
hw --api OSOffice --task check-with-cache --args V2016 test
```
### [7. 📖 点击Rust调用微软系统激活](examples/os_system.rs)
```bash
# 激活系统
hw --api OSSystem --task active --args XXXXX-XXXXX-XXXXX-XXXXX-XXXXX activation_temp
# 检查系统激活状态并查询激活码缓存
hw --api OSSystem --task check-with-cache --args activation_temp
```
### [8. 📖 点击Rust调用导出DLL|SO动态链接库](examples/file_info.rs)
```bash
# 导出DLL|SO动态链接库
hw --api FileInfo --task copy-lib --args target/debug/hw.exe target/debug/_libs
# 打印文件节点
hw --api FileInfo --task print --args target/debug/hw.exe
# 打印文件节点
hw --api FileInfo --task nodes --args target/debug/hw.exe
```
### [9. 📖 点击Rust调用PING](examples/ping.rs)
```bash
# 测试PING
hw --api OSMore --task NetManage --args ping 127.0.0.1 baidu.com 3
# 测试PING节点
hw --api OSMore --task NetManage --args ping-nodes baidu.com 3 -- ~is_connected Ethernet
```
### [10. 📖 点击Rust调用设置DHCP](examples/dhcp.rs)
```bash
# 设置DHCP ~is_connected 是指正在连接的网卡
hw --api OSMore --task NetManage --args dhcp -- ~is_connected
```
### [11. 📖 点击Rust调用设置静态IP](examples/static_ip.rs)
```bash
# 设置静态IP
hw --api OSMore --task NetManage --args set-ip 192.168.1.100 255.255.255.0 192.168.1.1 -- "以太网"
# 设置DNS Ethernet=类型 "以太网"=名称 ~is_connected=网卡
hw --api OSMore --task NetManage --args set-dns 223.5.5.5 114.114.114.114 "以太网" Ethernet ~is_connected
```
### [12. 📖 点击Rust调用桌面](examples/desktop.rs)
```bash
# 桌面节点
hw --api OSMore --task Desktop --args nodes
# 打印
hw --api OSMore --task Desktop --args print
```
### [13. 📖 点击Rust调用驱动](examples/drive.rs)
```bash
# 扫描驱动
hw --api Drive --task scan
# 驱动打印
hw --api Drive --task print -- =net "*I225-V #6"
hw --api Drive --task print -- "@pci*" "*I225-V #6"
hw --api Drive --task print -- "@pci*" "PCI*" "*E0276CFFFFEEA86B00"
# --full 完整数据 但更消耗资源,建议加=和@去筛选
hw --api Drive --task print --full -- =net "*I225-V #6"
# 驱动节点
hw --api Drive --task nodes -- =net
# 导出驱动
hw --api Drive --task export --args oem6.inf D:\\drives
hw --api Drive --task export --args oem*.inf .
# 重启驱动
hw --api Drive --task restart -- =net "Intel(R) Ethernet Controller (3) I225-V #5"
hw --api Drive --task restart -- "@PCI\VEN_8086&DEV_15F3&SUBSYS_00008086&REV_03\E0276CFFFFEEA86A00"
# 启用驱动
hw --api Drive --task enable -- =net "Intel(R) Ethernet Controller (3) I225-V #5"
# 禁用驱动
hw --api Drive --task disable -- "@PCI\VEN_8086&DEV_15F3&SUBSYS_00008086&REV_03\E0276CFFFFEEA86A00"
# 删除驱动
hw --api Drive --task delete -- "@PCI\VEN_8086&DEV_15F3&SUBSYS_00008086&REV_03\E0276CFFFFEEA86A00"
# 增加驱动
hw --api Drive --task add --args D:\\drives\\oem6.inf /install
# 增加驱动文件夹
hw --api Drive --task add-folder --args D:\\drives /install
# 检查驱动状态
hw --api Drive --task check-status
# 检查驱动状态并打印
hw --api Drive --task print-status
# 检查驱动状态并打印完整
hw --api Drive --task print-status --full
# 检查驱动状态并打印节点
hw --api Drive --task print-status --nodes
# 检查驱动状态并打印节点完整
hw --api Drive --task print-status --nodes --full
```
### [14. 📖 点击Rust调用同步时间](examples/sync_datetime.rs)
```bash
# 同步时间
hw --api OSMore --task NetManage --args sync-datetime time.windows.com
```
### [15. 📖 点击Rust调用网络接口](examples/net_interfaces.rs)
```bash
# "~Less100" 速度小于100
# "~100" 速度大于等于100
# "~1000" 速度大于等于1000
# "~Big1000" 速度大于等于10000
# "~is_connected" 正在连接
# "~has_dhcp_ip" 有DHCP IP
# 检查MAC重复和初始化
hw --api OSMore --task NetInterface --args check-mac "*I225-V #1" -- ~has_dhcp_ip
# 网络接口
hw --api OSMore --task NetInterface --args print -- ~has_dhcp_ip
# 网络接口节点
hw --api OSMore --task NetInterface --args nodes -- ~has_dhcp_ip
```
### [16. 📖 点击Rust调用磁盘](examples/disk.rs)
```bash
# 获取磁盘数据
hw --api Disk --task data --args C:
# 获取磁盘挂载树
hw --api Disk --task mount-tree --args C:
# 检查磁盘负载
hw --api Disk --task check-load --args 10 90
```
---
## 🚀 开发进度
| Backend |
Windows |
Linux |
MacOS |
Status |
Description |
支持功能 |
| CoreTemp |
✓
100%
|
-
0%
|
-
0%
|
✓已完成 |
获取硬件传感器数据 完成所有功能开发 |
HardwareType(硬件类型),SensorType(传感器类型) |
| OHM |
✓
100%
|
-
0%
|
-
0%
|
✓已完成 |
获取硬件传感器数据 完成所有功能开发 |
HardwareType(硬件类型),SensorType(传感器类型) |
| AIDA64 |
✓
100%
|
-
0%
|
-
0%
|
✓已完成 |
获取硬件传感器数据 完成所有功能开发 |
HardwareType(硬件类型),SensorType(传感器类型) |
| OS |
⚡
10%
|
⚡
10%
|
⚡
10%
|
🔄测试中 |
接口Rust system跨平台基础功能可用 支持更多的信息获取 |
CPU,RAM |
| OSMore |
⚡
70%
|
⚡
70%
|
⚡
70%
|
✓已完成 |
主要用于获取更多信息和管理 |
MemoryTotal(内存大小),CpuCoreCount(CPU内核数量),OsVersion(系统版本) OsFullVersion(系统版本),KernelVersion(内核版本),HostName(主机名),Uptime(开机时间) CpuUsage(CPU使用率),MemoryUsage(内存使用率),CpuArch(CPU架构),UserNames(用户名), NetInterface(网络接口),NetManage[网络管理(DHCP、PING、同步时间、静态IP配置)],Desktop(桌面),Drive(硬盘), |
| Drive |
✓
100%
|
⚡
0%
|
⚡
0%
|
✓已完成 |
对接PNPUTIL和devcon |
scan(扫描),add-folder(添加文件),add(添加),delete(删除),delete-find(删除并查找), print(打印),nodes(节点),restart(重启),enable(启用),disable(禁用),remove(移除),export(导出) |
| FileInfo |
✓
100%
|
⚡
99%
|
⚡
99%
|
✓已完成 |
获取文件的依赖dll或so,支持一键导出依赖 |
copy-lib(复制依赖),print(打印),nodes(列表) |
| OSSystem |
✓
100%
|
-
0%
|
-
0%
|
✓已完成 |
系统 |
check(检查),check-with-cache(检查并缓存),activate(激活),deactivate(注销),kms(注册kms),clear-kms(清理kms),clear-cache(清理缓存),cache-kms(缓存激活码) |
| OSOffice |
✓
90%
|
-
0%
|
-
0%
|
✓已完成 |
Office |
check(检查),check-with-cache(检查并缓存),activate(激活),kms(注册kms),clear-kms(清理kms),clear-cache(清理缓存),cache-kms(缓存激活码) |
> **Note**:
> - OpenHardwareMonitor (OHM) 和 AIDA64 仅支持 Windows 平台
> - sysinfo 支持跨平台但功能相对有限
> - 具体传感器支持可能因硬件而异
### 传感器类型支持详情
| Hardware Type |
Description |
Common Sensors |
| CPU |
中央处理器 |
Clock, Temperature, Load, Power |
| RAM |
内存 |
Data, Load, Clock |
| Mainboard |
主板 |
Temperature, Voltage, Fan |
| GpuNvidia |
NVIDIA显卡 |
Clock, Temperature, Load, Fan |
| GpuAti |
AMD/ATI显卡 |
Clock, Temperature, Load, Fan |
| HDD |
硬盘驱动器 |
Temperature, Load, Data |
| SuperIO |
Super I/O芯片 |
Fan, Temperature, Voltage |
| TBalancer |
T-Balancer设备 |
Fan, Flow, Temperature |
| Heatmaster |
Heatmaster设备 |
Fan, Flow, Temperature |
---
## 第三方接口版本
- OpenHardwareMonitor: v0.9.6
- AIDA64: v7.40.7100
- sysinfo: v0.33
### 关于第三方应用的说明
如果是用OHM 或 AIDA64接口,程序先会检查进程是否存在;
如果不存在则会检查当前目录是否存在 `OpenHardwareMonitor.exe` 或 `aida64.exe`
## 📊 性能基准
---
## 🦊 已运用项目
`AUTOTEST2.exe`
---
## 🔭 为什么选择这个工具?
在硬件监控领域,我们经常遇到以下挑战:
- 不同平台的监控接口差异大
- Windows下传感器数据获取复杂
- 支持Rust
- 缺乏统一的数据访问方式
- 多种监控工具切换繁琐
- 自动化测试支持有限
本工具致力于解决这些问题,提供:
### 🎯 统一的访问接口
- **命令行工具**: 简单直观的 CLI 命令
- **Rust API**: 原生的 Rust 编程接口
- **WMI 支持**: Windows 平台的 WMI 查询能力
- **Rust 支持**: Rust直接调用LIB
- **统一数据格式**: 标准化的数据输出
### 💻 多平台无缝支持
- **Windows**: 完整的传感器支持 (OHM/AIDA64)
- **Linux**: 基础系统信息监控 (sysinfo)
- **MacOS**: 基础系统信息监控 (sysinfo)
### 🔌 丰富的集成能力
- **自动化测试**: 支持自动化硬件测试场景
- **数据采集**: 灵活的数据收集和导出
- **监控告警**: 可配置的阈值监控
- **扩展接口**: 支持自定义监控后端
### 🛠️ 开箱即用
- **零配置**: 最小化配置需求
- **快速部署**: 单文件执行程序
- **向后兼容**: 保持 API 稳定性
- **完整文档**: 详细的使用说明
### 📊 典型应用场景
1. **硬件测试**
- 产品质量验证
- 性能基准测试
- 稳定性测试
2. **系统监控**
- 服务器状态监控
- 工作站性能分析
- 温控系统监测
3. **开发调试**
- 硬件驱动开发
- 性能优化分析
- 问题诊断
4. **自动化集成**
- CI/CD 管道集成
- 自动化测试脚本
- 监控系统对接
> 💡 **设计理念**:
> - 简单易用优先
> - 统一接口标准
> - 跨平台兼容
> - 可扩展架构
---
## 🙋 参考项目与资料
- [Open Hardware Monitor 官方文档](https://openhardwaremonitor.org/)
- [AIDA64 官方文档](https://www.aida64.com)
- [sysinfo Crates官方](https://crates.io/crates/sysinfo)
---
## 许可证
[LICENSE](LICENSE)
[COPYRIGHT](COPYRIGHT)
## 🤝 参与贡献
我们欢迎任何形式的贡献!
- 提交 Issue 报告 bug 或提出新功能建议
- 提交 Pull Request 改进代码
- 完善项目文档
- 分享使用经验
在提交 PR 之前,请确保:
1. 代码符合项目规范
2. 添加必要的测试
3. 更新相关文档
## 📜 开源协议
本项目采用 [MIT](LICENSE-MIT) 和 [Apache 2.0](LICENSE-APACHE) 双重协议。
---