使用lm-sensors和Net-SNMP监控计算机硬件

    • 1、lm-sensors简介
    • 2、lm-sensors下载
    • 3、安装lm-sensors依赖
    • 4、安装lm-sensors
    • 5、验证安装的lm-sensors
    • 6、安装Net-SNMP
    • 7、使用SNMP命令获取lm-sensors状态

1、lm-sensors简介

lm-sensors是一款linux的硬件监控的软件,可以帮助我们来监控主板,CPU的工作电压,风扇转速、温度等数据。这些数据我们通常在主板的 BIOS也可以看到。当我们可以在机器运行的时候通过lm_sensors随时来监测着CPU的温度变化,可以预防和保护因为CPU过热而会烧掉。

2、lm-sensors下载

lm-sensors的下载地址:https://github.com/groeck/lm-sensors

3、安装lm-sensors依赖

安装lm-sensors之前需要安装几个依赖的软件:

  • 编译时的依赖
 * GNU make
 * gcc
 * bison
 * flex
 * rrd header files (可选,用于传感器)
  • 运行时的依赖
* perl (用于sensors-detect)
* rrdtool >= 1.2.1 (可选,用于传感器)
* proper kernel configuration

我们只需要安装bisonflex即可:

sudo apt-get install bison
sudo apt-get install flex

4、安装lm-sensors

先解压,然后编译,最后安装。默认安装在/usr/local/目录下

unzip lm-sensors-master.zip
cd lm-sensors-master
make all
sudo make install

5、验证安装的lm-sensors

验证lm-sensors的版本,使用下面的命令:

in@v-m:~/learn/lm-sensors-master$ sensors -v
sensors version 3.4.0+SVN with libsensors version 3.4.0+SVN

lm-sensors使用之前需要使用sensors-detect命令去配置它。sensors-detect是一个与硬件传感器交互的脚本,运行下面的命令,然后按照屏幕提示进行操作。

in@v-m:~/learn/lm-sensors-master$ sudo sensors-detect 
# sensors-detect revision $Revision$
# System: VMware, Inc. VMware Virtual Platform [None]
# Board: Intel Corporation 440BX Desktop Reference Platform
# Kernel: 4.4.0-112-generic x86_64
# Processor: Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz (6/60/3)

This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you're doing.

Some south bridges, CPUs or memory controllers contain embedded sensors.
Do you want to scan for them? This is totally safe. (YES/no): YES
Module cpuid loaded successfully.
Silicon Integrated Systems SIS5595...                       No
VIA VT82C686 Integrated Sensors...                          No
VIA VT8231 Integrated Sensors...                            No
AMD K8 thermal sensors...                                   No
AMD Family 10h thermal sensors...                           No
AMD Family 11h thermal sensors...                           No
AMD Family 12h and 14h thermal sensors...                   No
AMD Family 15h thermal sensors...                           No
AMD Family 16h thermal sensors...                           No
AMD Family 17h thermal sensors...                           No
AMD Family 15h power sensors...                             No
AMD Family 16h power sensors...                             No
Intel digital thermal sensor...                             Success!
    (driver `coretemp')
Intel AMB FB-DIMM thermal sensor...                         No
Intel 5500/5520/X58 thermal sensor...                       No
VIA C7 thermal sensor...                                    No
VIA Nano thermal sensor...                                  No

Some Super I/O chips contain embedded sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no): YES
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor/ITE'...               Yes
Found unknown chip with ID 0x0200
Probing for Super-I/O at 0x4e/0x4f
Trying family `National Semiconductor/ITE'...               No
Trying family `SMSC'...                                     No
Trying family `VIA/Winbond/Nuvoton/Fintek'...               No
Trying family `ITE'...                                      No

Some systems (mainly servers) implement IPMI, a set of common interfaces
through which system health data may be retrieved, amongst other things.
We first try to get the information from SMBIOS. If we don't find it
there, we have to read from arbitrary I/O ports to probe for such
interfaces. This is normally safe. Do you want to scan for IPMI
interfaces? (YES/no): YES
Probing for `IPMI BMC KCS' at 0xca0...                      No
Probing for `IPMI BMC SMIC' at 0xca8...                     No

Some hardware monitoring chips are accessible through the ISA I/O ports.
We have to write to arbitrary I/O ports to probe them. This is usually
safe though. Yes, you do have ISA I/O ports even if you do not have any
ISA slots! Do you want to scan the ISA I/O ports? (YES/no): YES
Probing for `National Semiconductor LM78' at 0x290...       No
Probing for `National Semiconductor LM79' at 0x290...       No
Probing for `Winbond W83781D' at 0x290...                   No
Probing for `Winbond W83782D' at 0x290...                   No

Lastly, we can probe the I2C/SMBus adapters for connected hardware
monitoring devices. This is the most risky part, and while it works
reasonably well on most systems, it has been reported to cause trouble
on some systems.
Do you want to probe the I2C/SMBus adapters now? (YES/no): YES
Using driver `i2c-piix4' for device 0000:00:07.3: Intel 82371AB PIIX4 ACPI


Now follows a summary of the probes I have just done.
Just press ENTER to continue: 

Driver `coretemp':
  * Chip `Intel digital thermal sensor' (confidence: 9)

Do you want to generate /etc/sysconfig/lm_sensors? (yes/NO): YES
Copy prog/init/lm_sensors.service to /lib/systemd/system
and run 'systemctl enable lm_sensors.service'
for initialization at boot time.
Unloading cpuid... OK

然后重启系统。
使用sensors命令验证lm-sensors是否正常运行。输出示例如下:

in@v-m:~/learn/lm-sensors-master$ sensors
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +100.0°C  (high = +100.0°C, crit = +100.0°C)
Core 0:        +100.0°C  (high = +100.0°C, crit = +100.0°C)
Core 1:        +100.0°C  (high = +100.0°C, crit = +100.0°C)
Core 2:        +100.0°C  (high = +100.0°C, crit = +100.0°C)
Core 3:        +100.0°C  (high = +100.0°C, crit = +100.0°C)

可以看到采集到的温度都是+100.0°C,这是因为我的系统实在虚拟机上的原因,如果是真实的电脑,将会获得实际的温度。

6、安装Net-SNMP

Net-SNMP的安装可参考另外一篇文章:Net-SNMP安装

7、使用SNMP命令获取lm-sensors状态

启动snmpd

in@v-m:~/learn/lm-sensors-master$ sudo snmpd

使用snmpwalk命令获取lm-sensors的状态,如下:

in@v-m:~/learn/lm-sensors-master$ snmpwalk -v 2c -c public localhost lmSensors
LM-SENSORS-MIB::lmTempSensorsIndex.1 = INTEGER: 1
LM-SENSORS-MIB::lmTempSensorsIndex.2 = INTEGER: 2
LM-SENSORS-MIB::lmTempSensorsIndex.3 = INTEGER: 3
LM-SENSORS-MIB::lmTempSensorsIndex.4 = INTEGER: 4
LM-SENSORS-MIB::lmTempSensorsIndex.5 = INTEGER: 5
LM-SENSORS-MIB::lmTempSensorsDevice.1 = STRING: Physical id 0
LM-SENSORS-MIB::lmTempSensorsDevice.2 = STRING: Core 0
LM-SENSORS-MIB::lmTempSensorsDevice.3 = STRING: Core 1
LM-SENSORS-MIB::lmTempSensorsDevice.4 = STRING: Core 2
LM-SENSORS-MIB::lmTempSensorsDevice.5 = STRING: Core 3
LM-SENSORS-MIB::lmTempSensorsValue.1 = Gauge32: 100000
LM-SENSORS-MIB::lmTempSensorsValue.2 = Gauge32: 100000
LM-SENSORS-MIB::lmTempSensorsValue.3 = Gauge32: 100000
LM-SENSORS-MIB::lmTempSensorsValue.4 = Gauge32: 100000
LM-SENSORS-MIB::lmTempSensorsValue.5 = Gauge32: 100000

使用snmptable命令让lm-sensors数据显示在表格中,示例如下:

in@v-m:~/learn/lm-sensors-master$ snmptable -v 2c -c public localhost lmTempSensorsTable
SNMP table: LM-SENSORS-MIB::lmTempSensorsTable

 lmTempSensorsIndex lmTempSensorsDevice lmTempSensorsValue
                  1       Physical id 0             100000
                  2              Core 0             100000
                  3              Core 1             100000
                  4              Core 2             100000
                  5              Core 3             100000
in@v-m:~/learn/lm-sensors-master$ snmptable -v 2c -c public localhost lmFanSensorsTable
LM-SENSORS-MIB::lmFanSensorsTable: No entries
in@v-m:~/learn/lm-sensors-master$ snmptable -v 2c -c public localhost lmVoltSensorsTable
LM-SENSORS-MIB::lmVoltSensorsTable: No entries
in@v-m:~/learn/lm-sensors-master$ snmptable -v 2c -c public localhost lmMiscSensorsTable
LM-SENSORS-MIB::lmMiscSensorsTable: No entries

可以使用snmptranslate命令获取lm-sensors MIB树的结构:

in@v-m:~/learn/lm-sensors-master$ snmptranslate -Tp -IR lmSensors
+--lmSensors(16)
   |
   +--lmSensorsMIB(1)
   |
   +--lmTempSensorsTable(2)
   |  |
   |  +--lmTempSensorsEntry(1)
   |     |  Index: lmTempSensorsIndex
   |     |
   |     +-- -R-- Integer32 lmTempSensorsIndex(1)
   |     |        Range: 0..65535
   |     +-- -R-- String    lmTempSensorsDevice(2)
   |     |        Textual Convention: DisplayString
   |     |        Size: 0..255
   |     +-- -R-- Gauge     lmTempSensorsValue(3)
   |
   +--lmFanSensorsTable(3)
   |  |
   |  +--lmFanSensorsEntry(1)
   |     |  Index: lmFanSensorsIndex
   |     |
   |     +-- -R-- Integer32 lmFanSensorsIndex(1)
   |     |        Range: 0..65535
   |     +-- -R-- String    lmFanSensorsDevice(2)
   |     |        Textual Convention: DisplayString
   |     |        Size: 0..255
   |     +-- -R-- Gauge     lmFanSensorsValue(3)
   |
   +--lmVoltSensorsTable(4)
   |  |
   |  +--lmVoltSensorsEntry(1)
   |     |  Index: lmVoltSensorsIndex
   |     |
   |     +-- -R-- Integer32 lmVoltSensorsIndex(1)
   |     |        Range: 0..65535
   |     +-- -R-- String    lmVoltSensorsDevice(2)
   |     |        Textual Convention: DisplayString
   |     |        Size: 0..255
   |     +-- -R-- Gauge     lmVoltSensorsValue(3)
   |
   +--lmMiscSensorsTable(5)
      |
      +--lmMiscSensorsEntry(1)
         |  Index: lmMiscSensorsIndex
         |
         +-- -R-- Integer32 lmMiscSensorsIndex(1)
         |        Range: 0..65535
         +-- -R-- String    lmMiscSensorsDevice(2)
         |        Textual Convention: DisplayString
         |        Size: 0..255
         +-- -R-- Gauge     lmMiscSensorsValue(3)

参考:
Net-SNMP and lm-sensors on Ubuntu 10.04

你可能感兴趣的:(linux)