Linux常见的一些性能监控命令
文章目錄
- 全局監控
- top
- CPU監控
- uptime
- 內存監控
- free
- vmstat
- 磁盤監控
- df
- iostat
- 網絡監控
- netstat
- 進程監控
- ps
- lsof
在我們使用Linux進行開發、運維時,難免會出現一些問題,而要解決這些問題我們就需要獲取到系統當前的一些運行信息,來幫助我們快速鎖定問題的原由,下面就介紹幾個Linux常用的性能監控的命令。
全局監控
top
top用于按一定的順序顯示所有正在運行而且處于活動狀態的實時進程,而且會定期更新顯示結果。這條命令顯示了CPU的使用率、內存使用率、交換內存使用大小、高速緩存使用大小、緩沖區使用大小,進程PID、所使用命令以及其他。它還可以顯示正在運行進程的內存和CPU占用多的情況。
[lee@VM-0-6-centos ~]$ top top - 23:32:37 up 74 days, 13:49, 1 user, load average: 0.23, 0.44, 0.46 Tasks: 109 total, 1 running, 108 sleeping, 0 stopped, 0 zombie %Cpu(s): 1.3 us, 0.3 sy, 0.0 ni, 98.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 3880184 total, 151180 free, 1167056 used, 2561948 buff/cache KiB Swap: 0 total, 0 free, 0 used. 2414408 avail MemPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 15946 lee 20 0 2849664 484172 22256 S 2.0 12.5 3033:06 java1087 root 20 0 50088 968 636 S 1.3 0.0 1438:53 rshim3708 root 20 0 1026744 64760 11116 S 1.0 1.7 399:22.01 YDService 15922 root 20 0 205124 3144 1484 S 0.3 0.1 47:21.85 docker-proxy-cu 29931 root 20 0 742708 14424 2268 S 0.3 0.4 89:52.08 barad_agent1 root 20 0 125600 4180 2648 S 0.0 0.1 7:15.25 systemd2 root 20 0 0 0 0 S 0.0 0.0 0:05.53 kthreadd4 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H6 root 20 0 0 0 0 S 0.0 0.0 7:10.22 ksoftirqd/07 root rt 0 0 0 0 S 0.0 0.0 0:28.46 migration/08 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh9 root 20 0 0 0 0 S 0.0 0.0 38:42.32 rcu_schedCPU監控
uptime
uptime主要用于獲取當前時間、系統運行的時間、當前登錄用戶數,以及最近1、5、15分鐘的CPU負載情況。
[root@VM-0-6-centos lee]# uptime23:53:21 up 74 days, 14:10, 1 user, load average: 0.51, 0.27, 0.26內存監控
free
free主要用于監控內存與交換分區的使用情況。從左往右一次的參數為內存總量,已使用空間,未使用空間,共享內存,緩存,可用內存。
[lee@VM-0-6-centos ~]$ freetotal used free shared buff/cache available Mem: 3880184 1161644 149460 836 2569080 2419820 Swap: 0 0 0vmstat
vmstat命令是用于顯示虛擬內存、內核線程、磁盤、系統進程、I/O 模塊、中斷、CPU 活躍狀態等更多信息。
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st1 1 0 124908 135168 2455520 0 0 0 15 2 2 2 1 97 0 0磁盤監控
df
Linux中可以使用df命令來監控當前硬盤的使用情況。從左到右的參數依次為磁盤名、磁盤大小、已使用空間、剩余可使用空間、使用率、掛載點。
[lee@VM-0-6-centos ~]$ df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 1928476 0 1928476 0% /dev tmpfs 1940092 24 1940068 1% /dev/shm tmpfs 1940092 812 1939280 1% /run tmpfs 1940092 0 1940092 0% /sys/fs/cgroup /dev/vda1 51473868 10309776 38966848 21% / tmpfs 388020 0 388020 0% /run/user/0 tmpfs 388020 0 388020 0% /run/user/1000iostat
iostat是一個用于收集顯示系統存儲設備輸入和輸出狀態統計的簡單工具。這個工具常常用來追蹤存儲設備的性能問題,其中存儲設備包括設備、本地磁盤,以及諸如使用NFS等的遠端磁盤。(第三方包sysstat中)
[root@VM-0-6-centos lee]# iostat Linux 3.10.0-1160.11.1.el7.x86_64 (VM-0-6-centos) 07/31/2021 _x86_64_ (2 CPU)avg-cpu: %user %nice %system %iowait %steal %idle2.19 0.00 1.19 0.06 0.00 96.56Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn vda 3.49 0.26 30.56 1660614 196986440 scd0 0.00 0.02 0.00 138978 0網絡監控
netstat
netstat主要用于對網絡信息進行監控,包含如網絡連接、路由表、網絡接口統計等信息,同時也可以查看當前正在運行的端口。
[lee@VM-0-6-centos ~]$ netstat Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 VM-0-6-centos:34626 172.17.0.2:wap-wsp ESTABLISHED tcp 0 0 VM-0-6-centos:34644 172.17.0.2:wap-wsp ESTABLISHED tcp 0 0 VM-0-6-centos:ssh mail.xegyptgroup.:51518 ESTABLISHED tcp 0 0 VM-0-6-centos:58272 172.17.0.2:wap-wsp ESTABLISHED tcp 0 0 VM-0-6-centos:ssh 121.4.180.253:47440 TIME_WAIT tcp 0 52 VM-0-6-centos:ssh 61.49.248.105:58641 ESTABLISHED tcp 0 0 VM-0-6-centos:34606 172.17.0.2:wap-wsp ESTABLISHED tcp 0 1013 VM-0-6-centos:ssh 138.68.80.132:56406 ESTABLISHED tcp 0 0 VM-0-6-centos:50170 169.254.0.4:http TIME_WAIT tcp 0 0 VM-0-6-centos:ssh 61.49.248.105:58642 ESTABLISHED tcp 0 0 VM-0-6-centos:42322 169.254.0.55:lsi-bobcat ESTABLISHED tcp 0 0 VM-0-6-centos:ssh 220.85.233.146:48014 TIME_WAIT tcp 0 0 VM-0-6-centos:34634 172.17.0.2:wap-wsp ESTABLISHED tcp 0 0 VM-0-6-centos:34618 172.17.0.2:wap-wsp ESTABLISHED tcp 0 0 VM-0-6-centos:54574 169.254.0.55:webcache TIME_WAIT tcp 0 0 VM-0-6-centos:34632 172.17.0.2:wap-wsp ESTABLISHED tcp 0 0 VM-0-6-centos:34600 172.17.0.2:wap-wsp ESTABLISHED tcp6 0 0 172.21.0.6:wap-wsp 172.17.0.3:48028 ESTABLISHED進程監控
ps
ps主要用于查看進程的使用情況
[lee@VM-0-6-centos ~]$ ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 May18 ? 00:07:15 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 root 2 0 0 May18 ? 00:00:05 [kthreadd] root 4 2 0 May18 ? 00:00:00 [kworker/0:0H] root 6 2 0 May18 ? 00:07:10 [ksoftirqd/0] root 7 2 0 May18 ? 00:00:28 [migration/0] root 8 2 0 May18 ? 00:00:00 [rcu_bh] root 9 2 0 May18 ? 00:38:42 [rcu_sched] root 10 2 0 May18 ? 00:00:00 [lru-add-drain]lsof
lsof主要以列表的形式顯示打開的文件和進程,打開的文件主要包括磁盤文件、網絡套接字、管道、設備和進程。
[lee@VM-0-6-centos ~]$ lsof COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd 1 root cwd unknown /proc/1/cwd (readlink: Permission denied) systemd 1 root rtd unknown /proc/1/root (readlink: Permission denied) systemd 1 root txt unknown /proc/1/exe (readlink: Permission denied) systemd 1 root NOFD /proc/1/fd (opendir: Permission denied) kthreadd 2 root cwd unknown /proc/2/cwd (readlink: Permission denied) kthreadd 2 root rtd unknown /proc/2/root (readlink: Permission denied) kthreadd 2 root txt unknown /proc/2/exe (readlink: Permission denied) kthreadd 2 root NOFD /proc/2/fd (opendir: Permission denied) kworker/0 4 root cwd unknown /proc/4/cwd (readlink: Permission denied)總結
以上是生活随笔為你收集整理的Linux常见的一些性能监控命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ZooKeeper ZAB协议:崩溃恢复
- 下一篇: ElasticSearch探索之路(一)