hwmon 用途

主要是依照官方的手冊去實作即可 網路上其他論壇太舊的就不要看了

https://www.zabbix.com/documentation/2.2/manual/appendix/items/sensor

主要作法是

除了 sensors 可以跑之外,應該要先看看 sysfs 裡的資訊。大部份 sensor 資料都在這邊 /sys/class/hwmon/hwmon* , 所以可以根據檔名猜到用途, 而真正的value 就用 cat 就可以了。

我的 hwmon* 像這樣

ls -l  /sys/class/hwmon/hwmon*
lrwxrwxrwx 1 root root 0 Jul  7 16:29 /sys/class/hwmon/hwmon0 -> ../../devices/platform/coretemp.0/hwmon/hwmon0
lrwxrwxrwx 1 root root 0 Jul  7 16:29 /sys/class/hwmon/hwmon1 -> ../../devices/platform/coretemp.1/hwmon/hwmon1
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon10 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-001f/hwmon/hwmon10
lrwxrwxrwx 1 root root 0 Jul  7 16:29 /sys/class/hwmon/hwmon2 -> ../../devices/pci0000:00/0000:00:05.0/0000:15:00.0/hwmon/hwmon2
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon3 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-0018/hwmon/hwmon3
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon4 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-0019/hwmon/hwmon4
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon5 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-001a/hwmon/hwmon5
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon6 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-001b/hwmon/hwmon6
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon7 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-001c/hwmon/hwmon7
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon8 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-001d/hwmon/hwmon8
lrwxrwxrwx 1 root root 0 Jul  7 16:30 /sys/class/hwmon/hwmon9 -> ../../devices/pci0000:00/0000:00:1f.3/i2c-0/0-001e/hwmon/hwmon9

其中 coretemp 就是 cpu 相關。再看每一個 hwmon* 以 hwmon0 cpu 的為例

/sys/class/hwmon/hwmon0/device$ ls -l
total 0
lrwxrwxrwx 1 root root    0 Jul  7 16:29 driver -> ../../../bus/platform/drivers/coretemp
drwxr-xr-x 3 root root    0 Jul  7 16:29 hwmon
-r--r--r-- 1 root root 4096 Jul  7 16:29 modalias
-r--r--r-- 1 root root 4096 Jul  7 16:30 name
drwxr-xr-x 2 root root    0 Jul 31 10:17 power
lrwxrwxrwx 1 root root    0 Jul  7 16:30 subsystem -> ../../../bus/platform
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp11_crit
-r--r--r-- 1 root root 4096 Jul 31 10:17 temp11_crit_alar
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp11_input
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp11_label
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp11_max
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp12_crit
-r--r--r-- 1 root root 4096 Jul 31 10:17 temp12_crit_alar
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp12_input
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp12_label
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp12_max
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp2_crit
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp2_crit_alarm
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp2_input
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp2_label
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp2_max
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp3_crit
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp3_crit_alarm
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp3_input
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp3_label
-r--r--r-- 1 root root 4096 Jul  7 16:30 temp3_max
-rw-r--r-- 1 root root 4096 Jul 31 10:17 uevent

就可以看到各種不同的 temp* 溫度相關數據。當然正常不需要這樣看,只要下 sensors 就可以了。

$ sensors
coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +31.0°C  (high = +85.0°C, crit = +95.0°C)
Core 1:       +34.0°C  (high = +85.0°C, crit = +95.0°C)
Core 9:       +28.0°C  (high = +85.0°C, crit = +95.0°C)
Core 10:      +25.0°C  (high = +85.0°C, crit = +95.0°C)

coretemp-isa-0001
Adapter: ISA adapter
Core 0:       +22.0°C  (high = +85.0°C, crit = +95.0°C)
Core 1:       +28.0°C  (high = +85.0°C, crit = +95.0°C)
Core 9:       +25.0°C  (high = +85.0°C, crit = +95.0°C)
Core 10:      +23.0°C  (high = +85.0°C, crit = +95.0°C)

好了,接下來是 zabbix 的部份,接下來假設 zabbix_server and zabbix_agent 那些都運作正常要加溫度的 sensor 的步驟: 先登入 zabbix_server 主機,進行 zabbix_get 的測試

zabbix_get 語法大概是

NAME
       zabbix_get - Zabbix get utility.

   SYNOPSIS
          zabbix_get [-hV] [-s <host name or IP>] [-p <port number>] [-I <IP address>] [-k <item key>]

所以,很簡單的拿來試試看能不能透過 agent 去取的主機資訊。但最棘手的事 -k 著個 option。如果不熟悉的可以參考兩個連結 1. item-key 的運作 https://www.zabbix.com/documentation/2.2/manual/config/items/item/key 2. agent 有哪些內建的item https://www.zabbix.com/documentation/2.2/manual/config/items/itemtypes/zabbix_agent

ok, 可以找到

sensor[device,sensor,<mode>]  // Hardware sensor reading.   
device - device name
sensor - sensor name
mode - possible values:     avg, max, min (if this parameter is omitted, device and sensor are treated verbatim).

See a more detailed description of sensor item on Linux.
sensor[cpu0,temp0] - temperature of one CPU....

好了,可以用 sensor[device,sensor] 來知道溫度,zabbix sensor 範例是

sensor[k8temp-pci-00c3,temp, max] or sensor[0000:00:18.3,temp1]

所以第一個就是要知道 device,可以用 sensors -u

sensors -u
coretemp-isa-0000
Adapter: ISA adapter
Core 0:
temp2_input: 29.000
temp2_max: 85.000
temp2_crit: 95.000
temp2_crit_alarm: 0.000
Core 1:
temp3_input: 32.000
temp3_max: 85.000
temp3_crit: 95.000
temp3_crit_alarm: 0.000
Core 9:
temp11_input: 26.000
temp11_max: 85.000
temp11_crit: 95.000
Core 10:
temp12_input: 25.000
temp12_max: 85.000
temp12_crit: 95.000

以上 找到關鍵的 device coretemp-isa-0000, 再來就是 sensor 是 temp2 而 mode 有很多 input, max, crit...

# zabbix_get -s 140.110.240.67 -k sensor[coretemp-isa-0000,temp2, input]
30.000000

得到目前的溫度。

網頁的部份,就要再新增一個 configuration -> host -> select a host -> create item -> key

key 設定是 sensor[coretemp-isa-0000,temp2, input]

其他自己看需求填入

這樣就完成了

可以做主機溫度 sensor 了。

Comments