20個Linux命令行工具監(jiān)視性能
對于每一個系統(tǒng)管理員或網(wǎng)絡(luò)管理員每天監(jiān)視或調(diào)試linux系統(tǒng)的性能問題是一件非常困難的事,在it行業(yè)作為一個linux管理員五年之后,我開始知道監(jiān)視和保持系統(tǒng)啟動和運行有多么的困難。由于這個原因,我們編寫了20條常用的命令行工具,希望對每一個linux系統(tǒng)管理員有用。這些命令是可利用的在所有類型的linux之下并且對監(jiān)視和發(fā)現(xiàn)性能的實際原因是很有用的。這些列表的命令是足夠的對于你選擇適合你的任何一個監(jiān)控場景。
1,top ---linux process monitoring
top 命令是一個性能監(jiān)視程序,通常被許多系統(tǒng)管理員頻繁使用監(jiān)視linux性能并且能夠使用在不同的類型的linux之下。top命令用于顯示所有運行和活躍的實時進程并定期更新它。它顯示了cpu使用率,內(nèi)存使用率,交換內(nèi)存,緩存大小,緩沖區(qū)大小,進程pid,用戶,命令等等。它也展示了運行進程的高cpu利用率和內(nèi)存利用率。top命令對系統(tǒng)管理員監(jiān)視和在需要的時候采取正確的行動是非常的重要。下面讓我們看看top命令。
#top
了解top的更多帶參數(shù)的命令在shell中輸入“man top”。
2,VmStat -- Virtual Memory Statistic
VmStat命令用來顯示虛擬內(nèi)存, 內(nèi)核線程, 磁盤, 系統(tǒng)進程, 輸入輸出塊, 中斷, 活動的cpu 等等.默認的VmStat命令是不能直接被直接使用的,在linux系統(tǒng)下你必須安裝一個名叫sysstat的包,這個包包含Vmstat命令。這個命令的使用如下。
- procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
- r b swpd free inact active si so bi bo in cs us sy id wa st
- 1 0 0 810420 97380 70628 0 0 115 4 89 79 1 6 90 3 0
了解VmStat的更多命令請在shell中輸入“man vmstat”。
3, Lsof – List Open Files
Lsof命令用來顯示所有打開的文件和進程的一個列表。打開的文件包括磁盤文件, 網(wǎng)絡(luò)套接字, 管道, 設(shè)備 和 進程。使用這個命令的主要原因之一是當文件系統(tǒng)不能被卸載或者文件出現(xiàn)一個錯誤是文件正在被使用或打開。使用這個命令你能夠很容易的找到那個文件正在被使用。這個命令的使用格式如下。
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
init 1 root cwd DIR 104,2 4096 2 /
init 1 root rtd DIR 104,2 4096 2 /
init 1 root txt REG 104,2 38652 17710339 /sbin/init
init 1 root mem REG 104,2 129900 196453 /lib/ld-2.5.so
init 1 root mem REG 104,2 1693812 196454 /lib/libc-2.5.so
init 1 root mem REG 104,2 20668 196479 /lib/libdl-2.5.so
init 1 root mem REG 104,2 245376 196419 /lib/libsepol.so.1
init 1 root mem REG 104,2 93508 196431 /lib/libselinux.so.1
init 1 root 10u FIFO 0,17 953 /dev/initctl
了解更多的Lsof命令請直接打開shell輸入“man lsof”
4,Tcpdump -- Network Packet Analyzer
Tcpdump 是一個被廣泛使用的命令行工具,network packet analyzer(網(wǎng)絡(luò)包分析) 或packets sniffer(包嗅探) 命令 被用來 capture(捕獲) or filter(過濾) 接受或傳輸在連接網(wǎng)絡(luò)上的接口上的 TCP/IP 包,它也提供一個選項來保存捕獲的包在一個文件中之后進行分析。 tcpdump 也是有用的在分布的不同類型的linux中。tcpdump的使用如下。
# tcpdump -i eth0
- tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
- listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
- 22:08:59.617628 IP tecmint.com.ssh > 115.113.134.3.static-mumbai.vsnl.net.in.28472: P 2532133365:2532133481(116) ack 3561562349 win 9648
- 22:09:07.653466 IP tecmint.com.ssh > 115.113.134.3.static-mumbai.vsnl.net.in.28472: P 116:232(116) ack 1 win 9648
- 22:08:59.617916 IP 115.113.134.3.static-mumbai.vsnl.net.in.28472 > tecmint.com.ssh: . ack 116 win 64347
5,Netstat -- Network Statistics
Netstat 是一個監(jiān)視輸入和輸出網(wǎng)絡(luò)包統(tǒng)計的命令行工具,它是非常的有用對于每一個系統(tǒng)管理員監(jiān)視網(wǎng)絡(luò)性能和 網(wǎng)絡(luò)連接故障問題。使用方法如下。
# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:realm-rusd *:* LISTEN
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 localhost.localdomain:ipp *:* LISTEN
tcp 0 0 localhost.localdomain:smtp *:* LISTEN
tcp 0 0 localhost.localdomain:smtp localhost.localdomain:42709 TIME_WAIT
tcp 0 0 localhost.localdomain:smtp localhost.localdomain:42710 TIME_WAIT
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 *:https *:* LISTEN
netstat 的更多使用方法見“man netstat”。
6,Htop – Linux Process Monitoring
Htop 是一個更先進的交互和實時進程監(jiān)控工具。這和linux的top命令更相似但是Htop有更豐富的界面就像用戶友好的界面管理進程,快捷鍵,水平和垂直的視圖瀏覽進程等等。Htop是一個三部分的工具默認情況下沒有包含。你必須安裝它使用YUM包管理工具。
# htop
7,Iotop -- Monitor Linux Disk I/O
Iotop 也和top,htop命令相似, 但是它能監(jiān)視和顯示實時的磁盤I/O信息和進程信息。這個工具更有用對于查找而外的進程和高使用磁盤讀寫進程。
# iotop
8,Iostat – Input/Output Statistics
IoStat 是一個簡單的收集和顯示輸入輸出存儲設(shè)備的統(tǒng)計信息的工具。這個工具被用來追This to蹤存儲設(shè)備性能問題包括 devices(設(shè)備), local disks(本地磁盤), remote disks(遠程磁盤) such as NFS(網(wǎng)絡(luò)存儲文件)。
# iostat
Linux 2.6.18-238.9.1.el5 09/13/2012
avg-cpu: %user %nice %system %iowait %steal %idle
2.60 3.65 1.04 4.29 0.00 88.42
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
cciss/c0d0 17.79 545.80 256.52 855159769 401914750
cciss/c0d0p1 0.00 0.00 0.00 5459 3518
cciss/c0d0p2 16.45 533.97 245.18 836631746 384153384
cciss/c0d0p3 0.63 5.58 3.97 8737650 6215544
cciss/c0d0p4 0.00 0.00 0.00 8 0
cciss/c0d0p5 0.63 3.79 5.03 5936778 7882528
cciss/c0d0p6 0.08 2.46 2.34 3847771 3659776
9. IPTraf – Real Time IP LAN Monitoring
IPTraf 是一個開源的基于console的實時網(wǎng)絡(luò)監(jiān)視工具,它收集了不同種類的信息例如通過網(wǎng)絡(luò)的ip交通監(jiān)視。包括tcp flag信息,icmp信息,tcp/udp交通故障,tcp連接包和字節(jié)統(tǒng)計。它還收集接口的統(tǒng)計TCP、UDP、IP、ICMP、非IP,IP校驗和錯誤,界面活動的信息等。
10,Psacct or Acct -- Monitor User Activity
psacct or acct tools 是非常的有用對于監(jiān)視每一個用戶的活動, 這兩個守護進程在后臺運行并保持密切關(guān)注系統(tǒng)上的每個用戶的整體活動有什么資源被消耗。
這些工具是非常有用的對系統(tǒng)管理員追蹤每個用戶的活動例如用戶正在做什么,他們發(fā)布了什么命令,他們在使用多少資源,他們使用系統(tǒng)多久了等等。
How to Monitor User Activity with psacct or acct Tools
11,Monit –- Linux Process and Services Monitoring
Monit 是一個免費開源并且基于web的進程監(jiān)督實用程序,自動監(jiān)控和管理系統(tǒng)進程,應(yīng)用程序,文件,目錄,權(quán)限,校驗和和文件系統(tǒng)。
它監(jiān)視的服務(wù)有 Apache, MySQL, Mail, FTP, ProFTP, Nginx, SSH 等等。系統(tǒng)狀態(tài)能被瀏覽通過命令行或者使用Monit 自己的用戶界面。
想要了解Monit的更多的命令請參考Linux Process Monitoring with Monit 。
12,NetHogs –- Monitor Per Process Network Bandwidth
NetHogs is 是一個類似于top命令的開源的更好的更小的程序,它能夠監(jiān)視系統(tǒng)上的任何一個活動網(wǎng)絡(luò)進程。它也能夠記錄實時網(wǎng)絡(luò)流量帶寬使用的每個程序或應(yīng)用程序。
想要了解該命令的更多用法請參考Monitor Linux Network Bandwidth Using NetHogs 。
13,iftop -- Network Bandwidth Monitoring
iftop 是另一個基于終端的免費開源的系統(tǒng)監(jiān)控實用工具。它通過系統(tǒng)連接的網(wǎng)絡(luò)接口來顯示頻繁更新的網(wǎng)絡(luò)(源主機到目的主機)帶寬利用率。 iftop 被用作監(jiān)視網(wǎng)絡(luò)使用率,而‘top‘則被用來監(jiān)視cpu的使用率。 iftop工具被用來監(jiān)視被選擇的網(wǎng)絡(luò)接口并且顯示兩個主機之間的網(wǎng)絡(luò)帶寬使用情況。具體用法如下:
該命令的更多使用方法請參考iftop – Monitor Network Bandwidth Utilization 。
14,Monitorix -- System and Network Monitoring
Monitorix is 是一個免費的輕量級的實用工具,它主要被設(shè)計用來運行和監(jiān)視系統(tǒng)和網(wǎng)絡(luò)資源盡可能多的運用在Linux/Unix服務(wù)器上。它有一個內(nèi)置的web服務(wù)器能夠定期的收集系統(tǒng)和網(wǎng)絡(luò)的信息并且通過圖像顯示它們。 它監(jiān)視 system load average and usage, memory allocation(內(nèi)存分配), disk driver health(磁盤驅(qū)動的健康狀態(tài)), system services(系統(tǒng)服務(wù)), network ports(網(wǎng)絡(luò)端口), mail statistics (Sendmail, Postfix, Dovecot, etc)郵件統(tǒng)計, MySQL statistics (mysql統(tǒng)計)等等. 它旨在監(jiān)控系統(tǒng)整體性能和有助于檢測失敗,瓶頸,異常活動等。
了解該命令的更多使用方法請參考:Monitorix a System and Network Monitoring Tool for Linux 。
15,Arpwatch -- Ethernet Activity Monitor
Arpwatch is 是一種被設(shè)計用來監(jiān)視以太網(wǎng)的地址解析(MAC and IP address changes)的程序。 它持續(xù)保持監(jiān)視以太網(wǎng)流量和產(chǎn)生一個IP和MAC地址對變化的以及網(wǎng)絡(luò)上的時間戳的日志。當有一個地址對發(fā)生變化時它通過發(fā)送一個電子郵件界面告示管理員。它是非常的有用對于檢查網(wǎng)絡(luò)中ARP 攻擊。
# arpwatch -i eth0
# tail -f /var/log/messageseth0
Apr 15 12:45:17 tecmint arpwatch: new station 172.16.16.64 d0:67:e5:c:9:67
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
想要了解更多該命令的使用方法請參考:Arpwatch to Monitor Ethernet Activity
16,Suricata --Network Security Monitoring
Suricata 是一個高性能的開源網(wǎng)絡(luò)安全和入侵檢測和預防監(jiān)測系統(tǒng), FreeBSD 和 Windows.它由一個非盈利基金會OISF設(shè)計和使用。
# suricata -c /etc/suricata/suricata.yaml -i eth0
23/7/2013 -- 12:22:45 - - This is Suricata version 1.4.4 RELEASE
23/7/2013 -- 12:22:45 - - CPUs/cores online: 2
23/7/2013 -- 12:22:45 - - Found an MTU of 1500 for 'eth0'
23/7/2013 -- 12:22:45 - - allocated 2097152 bytes of memory for the defrag hash... 65536 buckets of size 32
23/7/2013 -- 12:22:45 - - preallocated 65535 defrag trackers of size 104
23/7/2013 -- 12:22:45 - - defrag memory usage: 8912792 bytes, maximum: 33554432
23/7/2013 -- 12:22:45 - - AutoFP mode using default "Active Packets" flow load balancer
23/7/2013 -- 12:22:45 - - preallocated 1024 packets. Total memory 3170304
23/7/2013 -- 12:22:45 - - allocated 131072 bytes of memory for the host hash... 4096 buckets of size 32
23/7/2013 -- 12:22:45 - - preallocated 1000 hosts of size 76
23/7/2013 -- 12:22:45 - - host memory usage: 207072 bytes, maximum: 16777216
23/7/2013 -- 12:22:45 - - allocated 2097152 bytes of memory for the flow hash... 65536 buckets of size 32
23/7/2013 -- 12:22:45 - - preallocated 10000 flows of size 176
23/7/2013 -- 12:22:45 - - flow memory usage: 3857152 bytes, maximum: 33554432
23/7/2013 -- 12:22:45 - - IP reputation disabled
23/7/2013 -- 12:22:45 - - using magic-file /usr/share/file/magic
了解該命令的更多使用方法請參考:Suricata – A Network Intrusion Detection and Prevention System。
17,VnStat PHP – Monitoring Network Bandwidth
VnStat PHP 一個基于web的前端應(yīng)用程序最受歡迎的網(wǎng)絡(luò)工具叫 “vnstat“. VnStat PHP 使用漂亮的圖形界面監(jiān)控網(wǎng)絡(luò)流量. 它顯示了發(fā)送和接收的網(wǎng)絡(luò)流量使用率在每小時,每周,每月的統(tǒng)計報告中。
該命令的更多用法參考:VnStat PHP – Monitoring Network Bandwidth 。
18,Nagios -- Network/Server Monitoring
Nagios是一個領(lǐng)先的開源強大的監(jiān)控系統(tǒng),讓網(wǎng)絡(luò)/系統(tǒng)管理員識別并解決服務(wù)器相關(guān)問題在影響主要業(yè)務(wù)流程之前。通過Nagios系統(tǒng), 管理員能夠遠程監(jiān)控系統(tǒng),交換機,路由器和打印機通過單一的窗口。 它顯示關(guān)鍵的警告和指示如果運行錯誤在你的網(wǎng)絡(luò)/服務(wù)器,它能夠間接地幫助你開始補救之前發(fā)生的錯誤。
具體使用方法請參考:: Install Nagios Monitoring System to Monitor Remote Linux/Windows Hosts 。
19, Nmon --Monitor Linux Performance
Nmon (stands for Nigel’s performance Monitor) 代表奈杰爾性能監(jiān)視器工具, 它被用來見識Linux資源例如 CPU, Memory, Disk Usage, Network, Top processes, NFS, Kernel 等等. 這個工具帶有兩種模式: Online Mode(在線模式) 和 Capture(捕獲模式) Mode.
在線模式,被用來實時監(jiān)控。抓包模式,被用來存儲那個包到格式為csv的文件中。
更多命令請參考:Install Nmon (Performance Monitoring) Tool in Linux 。
20,Collectl -- All-in-One Performance Monitoring Tool
Collectl is也是另外一個強大并且基于的豐富的命令行界面的實用工具。它能用來搜集linux的系統(tǒng)信息例如CPU usage(cpu使用率), memory(內(nèi)存), network(網(wǎng)絡(luò)), inodes(節(jié)點), processes(進程), nfs, tcp, sockets 等等。
更多命令參考:Install Collectl (All-in-One Performance Monitoring) Tool in Linux 。
英文鏈接:20 Command Line Tools to Monitor Linux Performance
譯文鏈接:http://www.cnblogs.com/Hackerman/p/3930505.html#top