我正在编写一个 API 来报告 Socket Daemon 查询的 IPMI 硬件信息,Socket Daemon 托管在客户端上,远程服务器将发送命令查询主机硬件状态。
我已经成功编写了一个 API,该 API 使用 FreeIPMI 库,来获取 CPU 和 M/B 的温度。在深入研究 ipmi-sensors 源代码后,我发现很难跳过输出到标准输出。为了获得标准输出,我使用dup(STDOUT_FILENO)
并重定向到管道,刷新管道,解析字符串内容,提取我需要的信息。
现在一切正常,但我面临另一个问题,我需要将 FreeIPMI 编译为静态库。
我找到了一个链接HOW to build freeipmi commands with static libraries instead of shared libraries,FreeIPMI Albert Chu的维护者说
./configure CFLAGS="-static"
编译静态库成功,ipmi-sensors编译失败,编译错误较多。如此沮丧。
之后,我在 FreeIPMI 项目文件夹ipmimonitoring- sensors.c 中找到另一个文件,使用命令编译
gcc -o ipmimonitoring-sensors ipmimonitoring-sensors.c -lipmimonitoring
是的,它有效。
sudo ./ipmimonitoring-sensors
Record ID, Sensor Name, Sensor Number, Sensor Type, Sensor State, Sensor Reading, Sensor Units, Sensor Event/Reading Type Code, Sensor Event Bitmask, Sensor Event String
3, CPU0_TEMP, 33, Temperature, Nominal, 46.00, C, 1h, C0h, 'OK'
12, DIMM_P0_B0, 4, Temperature, Nominal, 39.00, C, 1h, C0h, 'OK'
13, DIMM_P0_B1, 5, Temperature, Nominal, 40.00, C, 1h, C0h, 'OK'
59, P12V, 64, Voltage, Nominal, 12.06, V, 1h, C0h, 'OK'
60, P5V, 65, Voltage, Nominal, 4.99, V, 1h, C0h, 'OK'
61, P3V3, 66, Voltage, Nominal, 3.27, V, 1h, C0h, 'OK'
62, P5V_STBY, 67, Voltage, Nominal, 4.99, V, 1h, C0h, 'OK'
64, P_VBAT, 69, Voltage, Nominal, 3.22, V, 1h, C0h, 'OK'
65, P_VCCIN_P0, 70, Voltage, Nominal, 1.80, V, 1h, C0h, 'OK'
67, P_1V2_BXD, 72, Voltage, Nominal, 1.23, V, 1h, C0h, 'OK'
71, P_1V05_BXD, 76, Voltage, Nominal, 1.06, V, 1h, C0h, 'OK'
72, P_1V5_BXD, 77, Voltage, Nominal, 1.53, V, 1h, C0h, 'OK'
73, P_VCCSCFUSESUS, 78, Voltage, Nominal, 1.72, V, 1h, C0h, 'OK'
74, P_VCCKRHV_BXD, 79, Voltage, Nominal, 1.32, V, 1h, C0h, 'OK'
136, CPU0_FAN, 96, Fan, Nominal, 2700.00, RPM, 1h, C0h, 'OK'
185, CPU0, 156, Processor, Nominal, N/A, N/A, 6Fh, 80h, 'Processor Presence detected'
202, MB_TEMP1, 51, Temperature, Nominal, 50.00, C, 1h, C0h, 'OK'
205, SEL, 152, Event Logging Disabled, Nominal, N/A, N/A, 6Fh, 0h, 'OK'
但是,我怎样才能得到阈值,ipmi-sensors -v
我知道会报告Nominal
和。但我想报告,,不仅仅是事件。 Warning
Critical
Low
High
OK
Entity Instance Type: Physical Entity
Event/Reading Type Code: 1h
Lower Critical Threshold: 0.000000 C
Upper Critical Threshold: 60.000000 C
Lower Non-Critical Threshold: 5.000000 C
Upper Non-Critical Threshold: 55.000000 C
Lower Non-Recoverable Threshold: N/A
Upper Non-Recoverable Threshold: N/A
Sensor Min. Reading: -128.000000 C
Sensor Max. Reading: 127.000000 C
Normal Min.: 0.000000 C
Normal Max.: 54.000000 C
Nominal Reading: 35.000000 C
Sensor Reading: 50.000000 C
Sensor Event: 'OK'
提前致谢。