首先編譯的時候configure參數加上--with-mib-modules='ucd-snmp/diskio ip-mib/ipv4InterfaceTable'
默認的配置沒有這些模塊,需要加上
make;make install后,使用命令net-snmp-config --snmpconfpath查看配置文件的目錄
然后修改snmp.conf,添加 mibs +ALL
修改snmpd.conf,在rocommunity public default -V systemonly,把 -V systemonly去掉。這是設置權限,去掉后為能訪問全部
假設community為public
snmpwalk -v 2c -c public localhost
這時應該會出來好多好多信息
以下是Linux下一些常用的OID
CPU的
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
硬盤的
The snmpd.conf needs to be edited. Add the following (assuming a machine with a single ‘/’ partition):
disk / 100000 (or)
includeAllDisks 10% for all partitions and disks
The OIDs are as follows
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
以下是windows下常用的OID
CPU
.1.3.6.1.2.1.25.3.3.1.2
如果有一個雙核cpu則有2個值,顯示當前負載
內存,硬盤
內存跟硬盤都統一在mib2.host.hrStorage里 1.3.6.1.2.1.25.2
hrStorageType節點,hrStorageFixedDisk表示硬盤,hrStorageVirtualMemory是虛擬內存,hrStorageRam是內存
根據id號查:
hrStorageAllocationUnits是簇的大小
hrStorageSize是有多少簇,兩者想乘就是總容量
hrStorageUsed是已使用多少,跟總容量相除就是占用率
系統運行時間
System Uptime: .1.3.6.1.2.1.1.3.0
注:linux系統的話也可直接用uptime命令獲得
網絡設備的
ifIndex 1.3.6.1.2.1.2.2.1.1.0 端口索引號
ifDescr 1.3.6.1.2.1.2.2.1.2.0 端口描述
ifType 1.3.6.1.2.1.2.2.1.3.0 端口類型
ifMtu 1.3.6.1.2.1.2.2.1.4.0 最大傳輸包字節數
ifSpeed 1.3.6.1.2.1.2.2.1.5.0 端口速度
ifPhysAddress 1.3.6.1.2.1.2.2.1.6.0 物理地址
ifOperStatus 1.3.6.1.2.1.2.2.1.8.0 操作狀態
ifLastChange 1.3.6.1.2.1.2.2.1.9.0 上次狀態更新時間
ifInOctets 1.3.6.1.2.1.2.2.1.10.0 輸入字節數
ifInUcastPkts 1.3.6.1.2.1.2.2.1.11.0 輸入非廣播包數
ifInNUcastPkts 1.3.6.1.2.1.2.2.1.12.0 輸入廣播包數
ifInDiscards 1.3.6.1.2.1.2.2.1.13.0 輸入包丟棄數
ifInErrors 1.3.6.1.2.1.2.2.1.14.0 輸入包錯誤數
ifInUnknownProtos 1.3.6.1.2.1.2.2.1.15.0 輸入未知協議包數
ifOutOctets 1.3.6.1.2.1.2.2.1.16.0 輸出字節數
ifOutUcastPkts 1.3.6.1.2.1.2.2.1.17.0 輸出非廣播包數
ifOutNUcastPkts 1.3.6.1.2.1.2.2.1.18.0 輸出廣播包數
ifOutDiscards 1.3.6.1.2.1.2.2.1.19.0 輸出包丟棄數
ifOutErrors 1.3.6.1.2.1.2.2.1.20.0 輸出包錯誤數
ifOutQLen 1.3.6.1.2.1.2.2.1.21.0 輸出隊長
流量輸出的是計數器,單位是byte,32位
如果流量過大出現統計不正確的情況,就需要編譯時加上enable-mfd-rewrites參數,來支持64位的計數器