安装:
sudo apt-get install
snmp
sudo apt-get install
snmpd
sudo apt-get insatll
snmp-mibs-downloader
使用:
sudo download-mibs
snmpwalk
-v 2c -c public localhost hrMemory
报错:No
Such Object available on this agent at
解决方法:
snmpd.conf配置文件里的配置有问题,没有赋予localhost可访问权限
vi
/etc/snmp/snmpd.conf
将下面这一行
agentAddress udp:127.0.0.1:161 注释掉,即
#agentAddress udp:127.0.0.1:161
然后将原来的这一行
#agentAddress
udp:161,udp6:[::1]:161 去掉注释,即
agentAddress
udp:161,udp6:[::1]:161
这样便可以实现snmp的远程监听了。
但修改后cacti服务器还是无法监测到CPU、内存、流量的数据,所以需要再做如下修改:
在snmpd.conf中找到下面的内容
view
systemonly included
.1.3.6.1.2.1.1
view
systemonly included
.1.3.6.1.2.1.25.1
在下面加上一行
view
systemonly included
.1 80
这样就允许监听所有设备了。
完成所有修改后,重启snmp
service
snmpd restart
完成以上配置后发现:snmpwalk依旧报错
但是使用oid执行正常
snmpwalk
-v 2c -c public localhost .1.3.6.1.2.1.2.2.1.2
说明环境变量有问题:
vi /etc/profiles
添加:export
MIBS=all
source
/etc/profiles
再执行命令:snmpwalk
-c public -v 2c localhost
hrMemory
成功返回结果:
Unlinked
OID in IPATM-IPMC-MIB: marsMIB ::= { mib-2 57 }
Undefined
identifier: mib-2 near line 18 of
/usr/share/mibs/ietf/IPATM-IPMC-MIB
Bad
operator (INTEGER): At line 73 in
/usr/share/mibs/ietf/SNMPv2-PDU
Expected
"::=" (RFC5644): At line 493 in
/usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Expected
"{" (EOF): At line 651 in
/usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Bad
object identifier: At line 651 in
/usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Bad
parse of OBJECT-IDENTITY: At line 651 in
/usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
HOST-RESOURCES-MIB::hrMemorySize.0
= INTEGER: 7998460 KBytes
MIB Browser
http://ireasoning.com/mibbrowser.shtml
Sure, but how can I
install them ?
Fortunately there is
a package to deal with that.
$ sudo apt-get install snmp-mibs-downloader
|
It will
download the IETF MIB files and install themunder the
usual /usr/share/mibs/
If for
any reason you don’t see it happen force it with
snmpget localhost -v 2c -c
public.1.3.6.1.2.1.1.3.0 #uptime
snmpget localhost -v 2c -c
public.1.3.6.1.2.1.1.1.0
#systemversion
snmpwalk localhost -v 2c
-c
public.1.3.6.1.2.1.25.4.2.1.2 #
show all therunning processes with pid
snmpwalk localhost -v 2c
-c public .1.3.6.1.2.1.4.20 #
get ip info
snmpwalk -c public -v 1 -m ALL localhost .1.3.6.1.2.1.25.2.2 #取得系统总内存
Load
1 minute Load .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load .1.3.6.1.4.1.2021.10.1.3.3
CPU
percentage of user CPU time .1.3.6.1.4.1.2021.11.9.0
raw user cpu time .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time .1.3.6.1.4.1.2021.11.10.0
raw system cpu time .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time .1.3.6.1.4.1.2021.11.51.0
内存
Total Swap Size .1.3.6.1.4.1.2021.4.3.0
Available Swap Space .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine .1.3.6.1.4.1.2021.4.5.0
Total RAM used .1.3.6.1.4.1.2021.4.6.0
Total RAM Free .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory .1.3.6.1.4.1.2021.4.15.0
磁盘
Path where the disk is mounted .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes) .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk .1.3.6.1.4.1.2021.9.1.10.1
System Uptime .1.3.6.1.2.1.1.3.0
加载中,请稍候......