每个传感器芯片在 sysfs /sys/devices 数中都有自己的目录。要找到所有的传感器芯片, 从 /sys/class/hwmon/hwmon* 跟踪设备的符号链接更容易,这里 * 是个数字(0,1,2,...)。
对于虚拟设备,传感器读数在 /sys/class/hwmon/hwmon*/ 目录, 对于非虚拟设备,传感器读数在 /sys/class/hwmon/hwmon*/device 目录。 hwmon* 或 hwmon*/device 目录中一个叫name的文件 包含该芯片的名称, 它对应于传感器芯片所使用的内核驱动程序的名称。
每个文件只有一个传感器读取值。 在上面提到的目录中包含传感器读数的文件的命令常用方案是: <type><number>_<item>, where
可以通过 sensor-detect 和 sensors 工具获取主机上可用的传感器信息 (lm-sensors package: http://lm-sensors.org/). Sensors-detect 帮助确定哪些模块对于可用的传感器是必需的。当模块加载 sensors 程序时可以用来显示所有传感器芯片的读数。该程序使用的传感器读数的标记可以和常规的命名方案不同。 (<type><number>_<item> ):
这个标签允许用户决定使用什么样的硬件。 如果既没有 <type><number>_label 文件,配置文件中也没有label,那么硬件的类型可以由分配的名字(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”)将不起作用。
要找出实际的传感器名称,以便 Zabbix 用于检索传感器读数,请运行sensors -u。在输出中,可以观察到以下内容:
$ 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”。根据规范,这些是芯片引脚上的电压,一般来说可能需要缩放。
Zabbix 不仅可以检索电压(in)读数,还可以检索电流(curr)、温度(temp)和风扇速度(fan)读数。
(传感器读数从/proc/sys/dev/sensor目录获得)
例子: 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]