顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2015年9月27日 星期日

[Ubuntu] 設定 啟動 snmp, net-snmp

安裝
~# apt-get update
~# apt-get install snmp
~# apt-get install snmp-mibs-downloader

編輯 snmpd.conf
~# echo 'rocommunity public' > /etc/snmp/snmpd.conf

理論上在 snmpd.conf 設定中加入這一行 rocommunity public 好像就已經足夠了,其他設定都可以註解起來也都沒關係一樣,算是一種快速的懶人設定法吧。

重新啟動snmpd
~# service snmpd restart

測試看看,如果跑出一堆訊息的話,就算是完成了。
~# snmpwalk -v 2c -c public localhost

用 snmp 輸出其他系統資訊 ~# snmpwalk -v 2c -c public localhost [OID參數]
# .1.3.6.1.4.1.2021.4.5.0 輸出記憶體的總容量
~# snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.2021.4.5.0
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 2015680 kB

# .1.3.6.1.4.1.2021.4.6.0 輸出目前記憶體的使用量
~# snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.2021.4.6.0
UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 1525412 kB


其他可以用的 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位的計數器

參考資料
1. 利用net-snmp讀取windows,linux,snmp設備資料(cpu,記憶體,網卡)
2. SNMP – The Missing MIB
3.

2015年9月26日 星期六

[Ubuntu] 關閉 停用 irqbalance

關閉 停用 irqbalance

編輯 ~# vi /etc/default/irqbalance 修改以下設定:
# 找到下面這行設定
#ENABLED="1"
# 更改設定為0
ENABLED="0"


關閉 irqbalance 服務
~# service irqbalance stop
irqbalance stop/waiting


參考資料:
1. 深度剖析告訴你irqbalance有用嗎?
2. linux irqbalance 優化中斷
3. linux irqbalance 是做什麼的
4. Linux irqbalance、中斷和進程綁定CPU
5. 使用irqbalance服務實現中斷負載均衡
6. How do I disable irqbalance?



[Ubuntu] MRTG 2.x 安裝 Step by Step

apt-get install snmp snmpd
apt-get install mrtg

[snmpd.conf] 
先備份 
# cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak 

編輯 snmpd.conf 
# echo 'rocommunity public' > /etc/snmp/snmpd.conf 

很多人mrtg裝不起來,大多是因為snmpd.conf弄不好,不過我發現到一個可以偷吃步的方法!! 
打上這一行(注意空格),就全部ok嘍,夠輕鬆愉快吧!! 


重跑snmp 
# /etc/init.d/snmpd restart 

測試一下snmp 
snmpwalk localhost -c public -v 1 

跑出一堆訊息就成功嘍!! 

... 
... 
HOST-RESOURCES-MIB::hrSWRunPerfMem.21022 = INTEGER: 1304 KBytes 
HOST-RESOURCES-MIB::hrSWRunPerfMem.21023 = INTEGER: 1752 KBytes 
HOST-RESOURCES-MIB::hrSWRunPerfMem.26812 = INTEGER: 14788 KBytes 
IPV6-MIB::ipv6Forwarding.0 = INTEGER: notForwarding(2) 
IPV6-MIB::ipv6DefaultHopLimit.0 = INTEGER: 0 
---------------------------------------------------------------------- 
snmp搞好了,就成功一半嘍,其他的就沒啥大礙了! 

[安裝mrtg] 
apt-get install mrtg 

會詢問妳 
Make /etc/mrtg.conf owned by and readable only by the MRTG user? 
選擇Yes 

---------------------------------------------------------------------- 
[產生mrtg.cfg] 
cfgmaker --global "WorkDir: /var/www/mrtg" --global "Refresh: 600" --global "Interval: 5" --global "WriteExpires: Yes" --global "Language: big5" --global "options[_]: bits" --ifdesc=descr --ifref=descr public@127.0.0.1 > /etc/mrtg.cfg 

整行複製吧,不斷行!! 
---------------------------------------------------------------------- 
執行mrtg 
#mrtg /etc/mrtg.cfg 

執行3次,無錯誤訊息即可 

---------------------------------------------------------------------- 
[產生流量分析網頁index.html] 
indexmaker --columns=1 \ 
--output=/var/www/mrtg/index.html \ 
--title='Traffic Info' \ 
/etc/mrtg/mrtg.cfg 

或是... 
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html 

以上都一樣是產生 index.html 
---------------------------------------------------------------------- 
[觀看mrtg 流量分析表囉] 
http://your.domain.name/mrtg/index.html 

以上這樣就會有基本的 eth0 的流量分析了 

2015年9月22日 星期二

[Ubuntu] 停用 snmp 擾人的 log Message Connection from UDP: [127.0.0.1]:43976->[ 127.0.0.1]:161

不可否認的 snmp 會一直在 syslog 產生以下這類的訊息,大概 5 分鐘就會產生一條,一天24小時就會產生288條訊息,這的確是一種無止盡的嘮叨。

Sep 22 18:20:03 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:43799->[127.0.0.1]:161
Sep 22 18:25:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:44170->[127.0.0.1]:161
Sep 22 18:30:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:38358->[127.0.0.1]:161
Sep 22 18:35:03 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:41847->[127.0.0.1]:161
Sep 22 18:40:03 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:38820->[127.0.0.1]:161
Sep 22 18:45:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:57794->[127.0.0.1]:161
Sep 22 18:50:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:46374->[127.0.0.1]:161
Sep 22 18:55:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:59770->[127.0.0.1]:161
Sep 22 19:00:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:53427->[127.0.0.1]:161
Sep 22 19:05:03 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:56370->[127.0.0.1]:161
Sep 22 19:10:03 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:42871->[127.0.0.1]:161
Sep 22 19:15:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:55832->[127.0.0.1]:161
Sep 22 19:20:02 farm snmpd[25909]: Connection from UDP: [127.0.0.1]:45324->[127.0.0.1]:161


以下設定可以把 snmp 這類的訊息關閉

打開編輯 vi /etc/default/snmpd 加入:
# 將這一行註解起來
# SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux,mteTrigger,mteTriggerConf -p /var/run/snmpd.pid'

# 加入底下這一行
SNMPDOPTS='-Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'

存檔,重啟 service snmpd restart 這樣你就再也看不到這些惱人的訊息了。

參考文件:snmpd[]: Connection from UDP: [127.0.0.1]: