利用net-snmp讀取windows,linux,snmp設備資料(cpu,記憶體,網卡)

版主: stnet253

回覆文章
tony
文章: 585
註冊時間: 2012-02-26, 07:04
聯繫:

利用net-snmp讀取windows,linux,snmp設備資料(cpu,記憶體,網卡)

未閱讀文章 tony »

利用net-snmp讀取windows,linux,snmp設備資料(cpu,記憶體,網卡)
5人收藏此文章, 我要收藏發表於1年前(2011-03-25 11:57) , 已有4864次閱讀 共2個評論
首先編譯的時候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位的計數器
回覆文章

誰在線上

正在瀏覽這個版面的使用者:Semrush [Bot] 和 1 位訪客