2008/09/12

[ LOS ] CentOS Install and Setting SNMP

記錄一下最近玩 CentOS Linux 的心得在 CentOS 上要如何啟動 SNMP 網管資訊 ? 方式如下:

1.安裝及設定


# yum -y install net-snmp net-snmp-utils
# net-snmp-utils 是 snmpwalk 工具。

# chkconfig snmpd on # 開機自動 up。
# service snmpd start # 啟動 snmpd。
Starting snmpd: [ OK ]

# snmpwalk -c public -v 1 localhost system # 使用 snmpwalk 測試。

# vi /etc/snmp/snmpd.conf # 調整 snmp 設定檔。

# 找到下面前三行設定 Mark 起來
# com2sec notConfigUser default public
# group notConfigGroup v1 notConfigUser
# group notConfigGroup v2c notConfigUser

# 再加入 group 存取設定

com2sec local localhost public
com2sec mynetwork 192.168.10.0/24 public
com2sec mynetwork 203.xxx.xxx.0/24 public

group MyRWGroup any local
group MyROGroup any mynetwork

view all included .1 80

access MyROGroup "" any noauth 0 all none none
access MyRWGroup "" any noauth 0 all all all

syslocation CentOS 5.2 at ERA Taipei
syscontact

disk / 10000

# /etc/rc.d/init.d/snmpd restart # 修改snmpd.conf後一定要重新啟動 snmpd 新設定值才會生效。

2.手動測試

# snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.9.1.2.1 # 測試採用 snmpget 抓取資訊。
UCD-SNMP-MIB::dskPath.1 = STRING: /

# snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.9.1.3.1 # 抓取硬碟資訊
UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/mapper/VolGroup00-LogVol00

# snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.4.5.0 # 抓取實體記憶體大小。
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 385448

以下為 Linux 上的 CPU、Memory、Disk 三種 MIBs, OIDs 的值,皆可使用 snmpget 抓取

CPU Statistics

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

Memory Statistics

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

Disk Statistics

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

5 意見:

匿名 提到...

請問一下
那看網卡流量的oid是多少阿?
搜尋了很久 都沒找到
感謝!

4wei-diary 提到...

# snmpget -v 1 -c public localhost IF-MIB::ifOutOctets.1

4wei-diary 提到...

IF-MIB::ifOutOctets.1 = .1.3.6.1.2.1.2.2.1.16.1
#snmpwalk -v 1 -c public localhost .1.3.6.1.2.1.2.2.1.16.1

匿名 提到...

感謝
再請問一下
這個得到的值 是總流量而且是bytes?

4wei-diary 提到...

是跟 interface RX/TX 的 TX 一樣的流量,也就是 interface 的 Output,是 bytes 沒錯 ~ 轉 Mega/bits 除兩次 1024 再乘 8 就行 ~