每个传感器芯片都在sysfs /sys/devices树中拥有自己的目录。 要查找所有传感器芯片,最好遵循设备的符号链接 来自 /sys/class/hwmon/hwmon*,其中 * 是一个实际数字 (0,1,2,...)。
传感器读数位于 /sys/class/hwmon/hwmon*/ 中 虚拟设备的目录,或/sys/class/hwmon/hwmon*/device 非虚拟设备的目录。一个名为 name 的文件,位于其中 hwmon* 或 hwmon*/device 目录包含芯片的名称, 这对应于传感器使用的内核驱动程序的名称 芯片。
每个文件只有一个传感器读数。通用方案为 命名包含传感器读数的文件,这些文件位于任意一个内部的 上述提到的目录为: 类型<数字>_<监控项>,其中
有关在主机上可用的传感器信息可以被获取 使用 sensor-detect 和 sensors 工具(lm-sensors 软件包: Sensors-detect 有助于确定哪些 模块对于可用传感器而言是必需的。当模块被加载时 sensors 程序可用于显示所有传感器的读数。 芯片。本程序使用的传感器读数标签可以是 与通用命名方案不同 (类型<数>_<监控项> ):
/etc/sensors.conf 中进行搜索(也可能是其他文件 /etc/sensors3.conf(或不同的配置文件)用于名称替换。这种标签允许用户确定使用的是哪种硬件。如果 既没有 <type><number>_label file 也没有标签存在 配置 file 硬件类型可由以下方式确定: 名称属性(hwmon*/device/name)。传感器的实际名称,其 Zabbix_agent 接受的参数,可通过运行 sensors 程序获取 使用 -u 参数(sensors -u)。
在 sensor 程序中,可用的传感器按总线进行区分 类型(ISA 适配器、PCI 适配器、SPI 适配器、虚拟设备、ACPI 接口,HID 适配器)。
Each sensor chip gets its own directory in the sysfs /sys/devices tree. To find all sensor chips, it is easier to follow the device symlinks from /sys/class/hwmon/hwmon*, where * is a real number (0,1,2,...).
The sensor readings are located either in /sys/class/hwmon/hwmon*/ directory for virtual devices, or in /sys/class/hwmon/hwmon*/device directory for non-virtual devices. A file, named name, located inside hwmon* or hwmon*/device directories contains the name of the chip, which corresponds to the name of the kernel driver used by the sensor chip.
There is only one sensor reading value per file. The common scheme for naming the files that contain sensor readings inside any of the directories mentioned above is: <type><number>_<item>, where
The information regarding sensors available on the host can be acquired using sensors-detect and sensors tools (lm-sensors package). Sensors-detect helps to determine which modules are necessary for available sensors. When modules are loaded the sensors program can be used to show the readings of all sensor chips. The labeling of sensor readings, used by this program, can be different from the common naming scheme (<type><number>_<item> ):
<type><number>_label, then the label inside this file will be used instead of <type><number><item> name;<type><number>_label file, then the program searches inside the /etc/sensors.conf (could be also /etc/sensors3.conf, or different) for the name substitution.This labeling allows user to determine what kind of hardware is used. If there is neither <type><number>_label file nor label inside the configuration file the type of hardware can be determined by the name attribute (hwmon*/device/name). The actual names of sensors, which zabbix_agent accepts, can be obtained by running sensors program with -u parameter (sensors -u).
In the sensors program the available sensors are separated by the bus type (ISA adapter, PCI adapter, SPI adapter, Virtual device, ACPI interface, HID adapter).
由于各传感器芯片厂商对标签的命名方式可能不同,sensors命令输出的传感器标签通常无法直接使用。例如,sensors输出可能包含以下内容:
$ sensors
in0: +2.24 V (min = +0.00 V, max = +3.32 V)
Vcore: +1.15 V (min = +0.00 V, max = +2.99 V)
+3.3V: +3.30 V (min = +2.97 V, max = +3.63 V)
+12V: +13.00 V (min = +0.00 V, max = +15.94 V)
M/B Temp: +30.0°C (low = -127.0°C, high = +127.0°C)其中仅有一个标签可直接使用:
尝试使用其他标签(如Vcore或+12V)将无效:
通过run sensors -u命令可查询Zabbix实际可用的传感器名称。输出示例如下:
$ sensors -u
...
Vcore:
in1_input: 1.15
in1_min: 0.00
in1_max: 2.99
in1_alarm: 0.00
...
+12V:
in4_input: 13.00
in4_min: 0.00
in4_max: 15.94
in4_alarm: 0.00
...因此Vcore应通过in1查询,+12V应通过in4查询。根据specification说明,这些数值对应芯片引脚电压,通常需要进行比例换算。
Zabbix不仅能获取电压(in)读数,还可采集电流(curr)、温度(temp)和风扇转速(fan)数据。
(传感器读数来自 /proc/sys/dev/sensors 目录)
示例键值:sensor[w83781d-i2c-0-2d,temp1]
(传感器读数从 /sys/class/hwmon 目录中获取)
示例键值:
sensor[k8temp-pci-00c3,temp,max] 或 sensor[0000:00:18.3,temp1]
sensor[smsc47b397-isa-0880,in,avg] 或 sensor[smsc47b397.2176,in1]