天天看點

+++++++程序管理工具 top/htop/glances/dstat指令

pstree,ps,pgrep,pkill,pidof

top,htop

glance,pmap,

vmstat,dstat

kill

job,bg,fg,nohup

sar(記憶體),tsar,iosstat(磁盤IO),iftop(網絡接口資料)

顯示内容注釋

[string] 背景的核心線程

    1、線程内共享程序記憶體,共享打開檔案描述符(檔案内容)

    2、線程是程序的子機關

    3、排程、跟蹤困難

USER  PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<code>USER: 程序使用者</code>

<code>PID: 程序PID</code>

<code>%CPU: 運作占據CPU時間百分比</code>

<code>VSZ:虛拟記憶體集:可交換出的資料</code>

<code>RSS: 常駐記憶體集:不可交換出的資料</code>

<code>TTY: 通過哪個終端啟動</code>

<code>STAT:程序狀态</code>

<code>    </code><code>R(Running),S(Interrupt Sleeping),D(uninterrupt Sleeping),T(Stopped),z(zombie)</code>

<code>    </code><code>+,l + 前台,l背景</code>

<code>    </code><code>N,&lt; N:低優先級</code>

<code>    </code><code>s 上司程序, </code>

<code>START: 程序啟動時間</code>

<code>TIME: 程序運作過程占據CPU累積時長</code>

<code>COMMAND: 由什麼指令啟動的相關程序</code>

PR  NI    VIRT    RES    SHR S            

<code>PR 優先級</code>

<code>NI   Nice值</code>

<code>VIRT  相當于VRT </code>

<code>RES   相當于RSS</code>

<code>SHR   shared </code>

<code>S    STATE</code>

PPID PRI  PSR RTPRIO

<code>ppid: 父程序</code><code>id</code><code>,0代表 天造地設</code>

<code>PRI: priority</code>

<code>PSR: 運作在哪個cpu上</code>

<code>rtprio: realtime priority 實時優先級</code>

<code>C cpu編号</code>

<code>top</code> <code>- 目前系統時間 up 運作時長, 使用者數, 平均負載:過去1分鐘,5分鐘,15分鐘</code>

<code>    </code><code>平均負載:CPU隊列中等待運作的程序數</code>

<code>    </code> 

<code>%Cpu(s):  0.4 us,  0.2 sy,  0.0 ni, 99.2 </code><code>id</code><code>,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st</code>

<code>所有CPU: user space, system space, </code><code>nice</code> <code>, idle , wait , hardware interrupt, software interrupt, stole</code>

<code>us: 使用者空間占據cpu時間百分比</code>

<code>wa: 等待IO完成的時間。時間長建議換硬碟</code>

<code>st:被虛拟化技術偷走的時間</code>

1、pstree顯示程序樹

CentOS 7

<code>[root@izpo45bh60h6bsz ~]</code><code># pstree</code>

<code>systemd─┬─AliYunDun───13*[{AliYunDun}]</code>

CentOS 6

init(upstart)

CentOS 5

init

2、ps

System V 風格

ps option

    a 與終端相關的程序

    x 與終端無關的程序

    u 與使用者相關的程序

    Z 安全标簽

    o 自定義顯示格式

    常用組合: 

        # ps aux

        # ps axZ

        # ps axo ppid,psr,ni,pri,rtprio,cmd

BSD風格

    -e 相當于 ax

    -f/-F 顯示詳細資訊

    -H hierarchy 層級結構顯示

使用示例

System V

15

16

17

18

19

<code>[root@izpo45bh60h6bsz ~]# ps aux </code>

<code>USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND</code>

<code>[root@izpo45bh60h6bsz ~]# ps axZ </code>

<code>LABEL                             PID TTY      STAT   TIME COMMAND</code>

<code>[root@izpo45bh60h6bsz ~]# ps -ef </code>

<code>UID        PID  PPID  C STIME TTY          TIME CMD</code>

<code>[root@izpo45bh60h6bsz ~]# ps -eF </code>

<code>UID        PID  PPID  C    SZ   RSS PSR STIME TTY   TIME CMD</code>

<code>[root@izpo45bh60h6bsz ~]# ps -eFH | head -n </code><code>1</code>

<code>UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD</code>

<code>[root@izpo45bh60h6bsz ~]# ps -exo pid,ppid,ni,psr,pri,rtprio,time,cmd </code>

<code>  </code><code>PID  PPID  NI PSR PRI RTPRIO     TIME CMD</code>

3、pgrep,pkill

    pgrep [option] pattern

    pkill [option] pattern

        -u euid 有效使用者(suid的屬主) 

        -U uid 真實使用者

        -t terminal 與指定終端相關的程序

        -a 完整格式

        -l 顯示程序名

        -P PPID 顯示PPID的子程序清單

20

21

22

23

<code>[root@izpo45bh60h6bsz ~]# pgrep sshd</code>

<code>4472</code>

<code>10829</code>

<code>[root@izpo45bh60h6bsz ~]# pgrep sshd -l</code>

<code>4472</code> <code>sshd</code>

<code>10829</code> <code>sshd</code>

<code>[root@izpo45bh60h6bsz ~]# pgrep sshd -a</code>

<code>4472</code> <code>/usr/sbin/sshd -D</code>

<code>10829</code> <code>sshd: root@pts/</code><code>0</code>    

<code>[root@izpo45bh60h6bsz ~]# pgrep -P </code><code>4472</code>

<code>[root@izpo45bh60h6bsz ~]# pgrep -t pts/</code><code>0</code>

<code>10831</code>

<code>[root@izpo45bh60h6bsz ~]# pgrep -t pts/</code><code>0</code> <code>-l</code>

<code>10831</code> <code>bash</code>

<code>[root@izpo45bh60h6bsz ~]# pgrep -t pts/</code><code>0</code> <code>-a</code>

<code>10831</code> <code>-bash</code>

4、top指令

top option

    -d 重新整理時間間隔

    -b 批次顯示

    -n # 顯示多少批次 與-b連勝 

<code>[root@izpo45bh60h6bsz ~]</code><code># top -d 0.0000000000000000000000000000000001</code>

<code>[root@izpo45bh60h6bsz ~]</code><code># top -d 0.0000000000000000000000000000000001 -b</code>

<code>[root@izpo45bh60h6bsz ~]</code><code># top -d 0.0000000000000000000000000000000001 -b -n 10</code>

排序

    P %CPU 占據CPU百分比(過去幾秒占據CPU百分比:幾秒由重新整理定義)

    M %MEM

    T TIME

顯示

    uptime: l

    tasks及cpu: t

        每個cpu: 1

    Mem/Swap: m

修改

    殺死: k

    退出: q

    修改重新整理時間間隔: s

6、htop 互動式程序檢視指令

    Fedora-EPEL

擷取幫助

    F1

標明程序

    s syscall

    t tree ,層級結構顯示

    l 顯示程序打開的檔案

    a 設定程序和cpu親源性,程序隻能運作在某個cpu上,增加緩存命中率

    F6 &gt; 以指定字段排序

<code>[root@izpo45bh60h6bsz ~]</code><code># dnf install htop</code>

7、vmstat指令 虛拟記憶體工具virtual memory state

vmstat [delay[count]]

    delay 延遲幾秒重新整理一次

    count 重新整理幾次

-p partiton

記憶體資訊檢視

    vmstat -s

    /proc/memoinfo

vmstat注釋

<code>[root@izpo45bh60h6bsz ~]</code><code># vmstat</code>

<code>procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----</code>

<code> </code><code>r  b   swpd   </code><code>free</code>   <code>buff  cache   si   so    bi    bo   </code><code>in</code>   <code>cs us sy </code><code>id</code> <code>wa st</code>

<code> </code><code>3  0      0 208496  37940 465952    0    0    21     8  107  256  0  0 99  0  0</code>

procs 程序

r running

b block

memory 記憶體

swpd 交換記憶體使用的總量

free 空閑實體記憶體總量

buff 記憶體中buff大小

cache 記憶體中cache大小

swap 交換分區

si 從實體記憶體加載至swap的速率

so 從swap加載至實體記憶體的速率

io 

bi input 從磁盤加載至記憶體的速率(kb/s)

bo output 從記憶體加載至磁盤的速率

system 系統

in/int interrupt 中斷,每秒多少個中斷

cs   context switch 程序上下文切換次數(儲存現場和恢複現場的切換次數)

cpu 

us user space

sy system space/kernel space

id idle

wa wait 等待IO完成的時間比率

st stole 被虛拟化技術偷走的比率

8、pmap報告記憶體映射表

    pmap [-x|-p|-d|-q] pid

    -x extend顯示擴充格式

    -p 顯示映射的完整路徑

    -d 顯示裝置資訊

    -q 不顯示首尾資訊

    檢視記憶體映射表

        /proc/PID/maps

        pmap pid

    線性記憶體位址和實體位址映射關系

    程序隻知道線性位址

    1、程序将打開的檔案存儲在程序記憶體位址空間中,分段存儲

    2、程序劃分的空間為4K的整數倍(記憶體頁的大小為4K)

    3、heap堆、stack棧、anon: anonymous 匿名頁,程序自己存儲資料的位置,不能交換出去

<code>Address           Kbytes     RSS   Dirty Mode  Mapping</code>

<code>00007ff5a8000000     164      12      12 rw---   [ anon ]</code>

<code>00007ff5a8029000   65372       0       0 -----   [ anon ]</code>

<code>00007ff5ac94d000       4       0       0 -----   [ anon ]</code>

<code>00007ff5ac94e000    8192       8       8 rw---   [ anon ]</code>

<code>00007ff5ad14e000       4       0       0 -----   [ anon ]</code>

<code>00007ff5ad14f000    8192       8       8 rw---   [ anon ]</code>

<code>00007ff5ad94f000      16       8       0 r-x-- libuuid.so.1.3.0</code>

<code>00007ff5ad953000    2044       0       0 ----- libuuid.so.1.3.0</code>

<code>00007ff5adb52000       4       4       4 r---- libuuid.so.1.3.0</code>

<code>00007ff5adb53000       4       4       4 rw--- libuuid.so.1.3.0</code>

<code>00007ff5adb54000     228      40       0 r-x-- libblkid.so.1.1.0</code>

<code>00007ff5adb8d000    2048       0       0 ----- libblkid.so.1.1.0</code>

<code>00007ff5add8d000      12      12      12 r---- libblkid.so.1.1.0</code>

<code>00007ff5add90000       4       4       4 rw--- libblkid.so.1.1.0</code>

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

<code>1、預設</code>

<code>[root@izpo45bh60h6bsz ~]</code><code># pmap  1 | head</code>

<code>1:   </code><code>/usr/lib/systemd/systemd</code> <code>--switched-root --system --deserialize 21</code>

<code>00007ff5a8000000    164K rw---   [ anon ]</code>

<code>00007ff5a8029000  65372K -----   [ anon ]</code>

<code>00007ff5ac94d000      4K -----   [ anon ]</code>

<code>00007ff5ac94e000   8192K rw---   [ anon ]</code>

<code>00007ff5ad14e000      4K -----   [ anon ]</code>

<code>00007ff5ad14f000   8192K rw---   [ anon ]</code>

<code>00007ff5ad94f000     16K r-x-- libuuid.so.1.3.0</code>

<code>00007ff5ad953000   2044K ----- libuuid.so.1.3.0</code>

<code>00007ff5adb52000      4K r---- libuuid.so.1.3.0</code>

<code>2、顯示詳細</code>

<code>[root@izpo45bh60h6bsz ~]</code><code># pmap -x 1 | head</code>

<code>3、靜默</code>

<code>[root@izpo45bh60h6bsz ~]</code><code># pmap -xq 1 | head</code>

<code>4、顯示完整map</code>

<code>[root@izpo45bh60h6bsz ~]</code><code># pmap -xqp 1 | head</code>

<code>00007ff5ad94f000      16       8       0 r-x-- </code><code>/usr/lib64/libuuid</code><code>.so.1.3.0</code>

<code>00007ff5ad953000    2044       0       0 ----- </code><code>/usr/lib64/libuuid</code><code>.so.1.3.0</code>

<code>00007ff5adb52000       4       4       4 r---- </code><code>/usr/lib64/libuuid</code><code>.so.1.3.0</code>

9、glances指令

    galances [options...] 

         -s -B IPADDR 服務端模式

        -c IPADDR   用戶端模式

            b 以位元組顯示網絡速率

            m/n/d 控制mount,network,disk子產品的顯示

            t # 延遲間隔

            1 每個cpu資訊單獨顯示

          -f /path/to/somefile galance顯示的結果儲存至檔案中

        -o {HTML|CSV} 檔案的格式

    galance内建指令

<code>  </code><code>a  Sort processes automatically     l  Show</code><code>/hide</code> <code>logs</code>

<code>  </code><code>c  Sort processes by CPU%           b  Bytes or bits </code><code>for</code> <code>network I</code><code>/O</code>

<code>  </code><code>m  Sort processes by MEM%           w  Delete warning logs</code>

<code>  </code><code>p  Sort processes by name           x  Delete warning and critical logs</code>

<code>  </code><code>i  Sort processes by I</code><code>/O</code> <code>rate       1  Global CPU or per-CPU stats</code>

<code>  </code><code>d  Show</code><code>/hide</code> <code>disk I</code><code>/O</code> <code>stats         h  Show</code><code>/hide</code> <code>this help </code><code>screen</code>

<code>  </code><code>f  Show</code><code>/hide</code> <code>file</code> <code>system stats      t  View network I</code><code>/O</code> <code>as combination</code>

<code>  </code><code>n  Show</code><code>/hide</code> <code>network stats          u  View cumulative network I</code><code>/O</code>

<code>  </code><code>s  Show</code><code>/hide</code> <code>sensors stats          q  Quit (Esc and Ctrl-C also work)</code>

<code>  </code><code>y  Show</code><code>/hide</code> <code>hddtemp stats</code>

    服務端

<code>[root@localhost ~]</code><code># glances -s -B 192.168.1.103 -p 8888 -P 1234</code>

<code>Glances server is running on 192.168.1.103:8888</code>

    用戶端

<code>[root@localhost ~]# glances -c </code><code>192.168</code><code>.</code><code>1.103</code> <code>-p </code><code>8888</code>

<code>Error: Connection to server failed. Bad password.</code>

<code>[root@localhost ~]# glances -c </code><code>192.168</code><code>.</code><code>1.103</code> <code>-p </code><code>8888</code> <code>-P </code><code>1234</code>

<code>[root@localhost ~]# </code>

<code>Connected to </code><code>192.168</code><code>.</code><code>1.103</code> <code>| Press </code><code>'h'</code> <code>for</code> <code>help</code>

10、dstat指令

    vmstat替換工具

        dstat options

            -c/-C #,#,..,total

            -d/-D total,/dev/sda,/dev/sdb,...

            -g page顯示記憶體資料交換的速率

            -i 顯示中斷速率

            -l --load 顯示平均負載

            -m,--mem 顯示記憶體資訊

            -n,--net 顯示網絡資訊

            -p,--proc 程序狀态

            -r,--io   顯示io相關的統計資料

            -s,--swap 顯示swap 相關的統計資料

            -t,--time 時間輸出

            --aio 異步io

            --fs,--filesystem 顯示檔案系統

            --ipc (message queue(signal),semephores,shared memory)

            --lock 檔案鎖

            --socket (total,udp,tcp,raw,ip-fragment分片)

            --tcp (listen,established,syn,time_wait,close)

            --udp (listen,active)

            --unix (datagram, stream, listen, active)

            PLUGIN:

                -a,相當于 -cdngy

    --battery 電池

    --battery-remain 電池剩餘的時間(ACPI支援)

    --disk-tps 磁盤每秒鐘的事務量(need ACPI)

    --mysql5-conn 對mysql運作指令的統計

                --top-cpu   顯示最消耗CPU的程序

                --top-int   顯示中斷資料最大的程序

                --top-io    最消耗IO的程序

                --top-mem    最消耗記憶體的程序

                --top-latency 顯示延遲最大的程序              

<code>----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--</code>

<code>usr sys idl wai hiq siq| read  writ| recv  send|  </code><code>in</code>   <code>out | </code><code>int</code>   <code>csw </code>

<code>total-cpu-usage cpu使用狀态</code>

<code>dsk/total       磁盤讀寫速率</code>

<code>net/total       網絡的收發速率</code>

<code>paging          頁面的換進換出(記憶體頁面,交換記憶體。 si,so)</code>

<code>system          中斷和上下文切換 (</code><code>int</code><code>: interrupt, csw: context swtich。 </code><code>in</code><code>,cs )</code>

1、cpu相關的資訊

<code>[root@localhost ~]</code><code># dstat  -c</code>

<code>----total-cpu-usage----</code>

<code>usr sys idl wai hiq siq</code>

<code>[root@localhost ~]</code><code># dstat  -C total,0</code>

<code>Terminal width too small, trimming output.</code>

<code>----total-cpu-usage------------cpu0-usage------ -dsk</code><code>/total-</code> <code>-net</code><code>/total-</code> <code>---paging--&gt;</code>

<code>usr sys idl wai hiq siq:usr sys idl wai hiq siq| </code><code>read</code>  <code>writ| recv  send|  </code><code>in</code>   <code>out &gt;</code>

2、硬碟相關

<code>[root@localhost ~]</code><code># dstat  -d</code>

<code>-dsk</code><code>/total-</code>

<code>read</code>  <code>writ  </code>

<code>[root@localhost ~]</code><code># dstat  -D total,/dev/sda</code>

<code>----total-cpu-usage---- -dsk</code><code>/total----dsk/sda--</code> <code>-net</code><code>/total-</code> <code>---paging-- ---system--</code>

<code>usr sys idl wai hiq siq| </code><code>read</code>  <code>writ: </code><code>read</code>  <code>writ| recv  send|  </code><code>in</code>   <code>out | int   csw</code>

3、頁面

<code>[root@localhost ~]# dstat  -g</code>

<code>---paging--</code>

4、顯示中斷

<code>[root@localhost ~]</code><code># dstat  -i</code>

<code>----interrupts---</code>

5、平均負載

<code>[root@localhost ~]# dstat  -l</code>

<code>---load-avg---</code>

<code> </code><code>1m   5m  15m</code>

6、記憶體

<code>[root@localhost ~]</code><code># dstat -m</code>

<code>------memory-usage-----</code>

<code> </code><code>used  buff  cach  </code><code>free</code>

7、網絡

<code>[root@localhost ~]</code><code># dstat -n</code>

<code>-net</code><code>/total-</code>

<code> </code><code>recv  send</code>

8、程序

<code> </code><code>---procs---</code>

<code>run blk new</code>

<code>  </code><code>run 運作程序的資料</code>

<code>  </code><code>new 建立新程序的資料</code>

9、io

<code>[root@localhost ~]</code><code># dstat -r</code>

<code>--io</code><code>/total-</code>

<code> </code><code>read</code>  <code>writ</code>

10、swap

<code>[root@localhost ~]</code><code># dstat -s</code>

<code>----swap---</code>

<code> </code><code>used  </code><code>free</code>

11、時間

<code>[root@localhost ~]</code><code># dstat -t</code>

<code>----system----</code>

<code>  </code><code>date</code><code>/time</code>

12、異步IO

<code>[root@localhost ~]</code><code># dstat --aio</code>

<code>async</code>

<code> </code><code>#aio</code>

13、檔案系統

<code>[root@localhost ~]</code><code># dstat --fs</code>

<code>--filesystem-</code>

<code>files  inodes</code>

14、程序通信

<code>[root@localhost ~]</code><code># dstat --ipc</code>

<code>--sysv-ipc-</code>

<code>msg sem shm</code>

15、檔案鎖

<code>[root@localhost ~]</code><code># dstat --lock</code>

<code>---</code><code>file</code><code>-locks--</code>

<code>pos lck rea wri</code>

16、套接字

<code>[root@localhost ~]</code><code># dstat --socket</code>

<code>------sockets------</code>

<code>tot tcp udp raw frg</code>

17、tcp連接配接

<code>[root@localhost ~]</code><code># dstat --tcp</code>

<code>----tcp-sockets----</code>

<code>lis act syn tim clo</code>

18、udp連接配接

<code>[root@localhost ~]</code><code># dstat --udp</code>

<code>--udp--</code>

<code>lis act</code>

19、unix連接配接

<code>[root@localhost ~]</code><code># dstat --unix</code>

<code>--unix-sockets-</code>

<code>dgm str lis act</code>

20、-a

<code>[root@localhost ~]</code><code># dstat -a 1 1</code>

<code>----total-cpu-usage---- -dsk</code><code>/total-</code> <code>-net</code><code>/total-</code> <code>---paging-- ---system--</code>

<code>usr sys idl wai hiq siq| </code><code>read</code>  <code>writ| recv  send|  </code><code>in</code>   <code>out | int   csw</code>

<code>[root@localhost ~]</code><code># dstat  --disk-util</code>

<code>sda-</code>

<code>util</code>

22、檔案系統空閑

<code>[root@localhost ~]</code><code># dstat  --freespace</code>

<code>-----</code><code>/----------/shm-------/boot-------/home--------/usr--------/var---</code>

<code> </code><code>used  </code><code>free</code><code>: used  </code><code>free</code><code>: used  </code><code>free</code><code>: used  </code><code>free</code><code>: used  </code><code>free</code><code>: used  </code><code>free</code>

<code>3101M 44.9G:   0   121M:57.4M  419M: 260M 4534M:2091M 12.3G: 714M 9001M</code>

23、插件注釋

<code>[root@localhost ~]</code><code># dstat  --helloworld</code>

<code>plugin-title</code>

<code>  </code><code>counter   </code>

<code>Hello world!</code>

24、最消耗cpu程序

<code>[root@izpo45bh60h6bsz ~]</code><code># dstat --top-cpu</code>

<code>-most-expensive-</code>

<code>  </code><code>cpu process   </code>

<code>AliYunDun    0.2</code>

<code>aliyun-servic1.0</code>

25、中斷次數最多

<code>[root@izpo45bh60h6bsz ~]</code><code># dstat --top-in</code>

<code>---most-frequent----</code>

<code>     </code><code>interrupt      </code>

<code>ata_piix          1 </code>

<code>virtio0-input.0   1</code>

26、io次數

<code>----most-expensive----</code>

<code>     </code><code>i</code><code>/o</code> <code>process      </code>

<code>systemd      29k   10k</code>

<code>sshd: root@ 146B  196B</code>

27、記憶體消耗最大

<code>[root@izpo45bh60h6bsz ~]# dstat --top-mem</code>

<code>--most-expensive-</code>

<code>  </code><code>memory process </code>

<code>mysqld       123M</code>

28、延遲最大的程序

<code>[root@izpo45bh60h6bsz ~]</code><code># dstat  --top-latency</code>

<code>--highest-total--</code>

<code> </code><code>latency process </code>

<code>rcu_sched     882</code>

11、kill指令

    檢視信号:

        kill -l

        man 7 signal

SIGHUP:   不關閉程序重讀配置檔案。服務程式

SIGINT:   終止信号(interrupt) 相當于 Ctrl + c

SIGKILL:  殺死正在運作的程序   ,直接終止,

SIGTERM:  終止指定的程序(優雅) ,處理的資料存回磁盤中,再終止 

SIGCONT 讓停止态的信号,continue

SIGSTOP 讓運作中的程序,stop

    SIGNAL:

        1、全名 SIGHUP

        2、簡名 HUP

        3、數字辨別 1

    發信号

        kill -SIGNAL pid

        killall -SIGNAL 程序名

12、作業

    jobs一個任務可能包含單個程序也可能包含多個程序

    前台作業:與終端相關,占據指令提示符

    背景作業:與終端相關,不占據指令提示符

    送到背景剝離與終端關系: # nohup COMMMAND &amp;

    作業送到背景:

        運作中的程式:Ctrl + z

        尚未啟動的程式:COMMAND &amp;

    檢視作業: # jobs

        + 沒有作業号,預設管理的作業

        - 下一個

        [#]作業号

    作業管理

        送到前台: fg [[%]JOB_NUM]

        送到背景: bg [[%]JOB_NUM]

        終止作業: kill -SIGNAL %JOB)NUM

13、nice值

    動态優先級:程序消耗過多的cpu資源時,核心自動調整,

    靜态優先級: 100-139 (資料越小,優先級越高)

     實時優先級: 0-99 (數字越大,優先級越高)

    程序預設啟動優先級120,nice值為 0

    nice [-n # ] command

        -n # 啟動後以#值作為Nice值運作,不給-n #,預設nice=10

    renice -n # command

        -n # 重新設定優先級

    檢視nice值: # ps axo pid,command,ni

14、sar,tsar,iosar,iftop

sar 

    -u cpu

    -d disk

    -B 交換頁資料

    -b 報告I\O傳輸速率

詳解:-B

pgpgin/s pgpgout/s   fault/s  majflt/s  pgfree/s pgscank/s pgscand/s pgsteal/s   

pgpgin/s  實體記憶體到磁盤swap

fault 缺頁異常發生的速率

majflt/s  major faults 

pgfree/s  page free place on

pgscank/s kswapd daemon scan pages

pgscnd/s  page scan directly

pgsteal/s page reclaimed from cache(pagecache and swap-cache)  

詳解: -u 報告cpu使用率

 CPU     %user     %nice   %system   %iowait    %steal     %idle

詳解: -b  

tps      rtps      wtps   bread/s   bwrtn/s

t 總傳輸

rtps 讀傳輸

wtps 寫傳輸

bread/s  從塊讀

bwrtn/s  寫到塊

tsar

iostat

Report Central Processing Unit (CPU) statistics and input/output statistics

       for devices and partitions.

 Central Processing Unit (CPU) 中央處理單元cpu

 statistics 統計資料

 for prep.為,為了;傾向于;關于;當作

    為裝置和分區報告CPU,I/O統計資料

    iostat [-u | -d | -h | -k | -m]

        -u cpu

        -d disk

        -h human readable

        -k KB

        -m MB

        -N LVM2統計資料

CPU Utilization Report(Utilization 使用率)

 %user 運作使用者級别/使用者空間的程序CPU使用率百分比

 %nice nice priority占據CPU利用百分比

 %system system level(kernel)

 %iowait 系統有突出IO時,CPU空閑百分比。程序等待IO的百分比

 %steal 被虛拟化技術偷走的時間

 %idle CPU空閑和系統無IO所占時間百分比

Device Utilization Report

  Device 顯示dev目錄下的裝置或Partition名

  tps 顯示每秒IO請求傳輸至裝置的數量,IO請求可以是單個,或多個IO請求組合成單個,大小不确定

kB_read/s     每秒從塊或扇區讀取資料量

kB_wrtn/s     每秒寫

kB_read      總讀

kB_wrtn      總寫

rrqm/s      queued to device read request merged 合并讀請求隊列的速率

wrqm/s      合并寫請求速率

iftop

1)擷取指令的資訊 指令行模式顯示網絡接口帶寬統計資料“為什麼我的ADSL連接配接如此慢”

<code>[root@izpo45bh60h6bsz ~]# dnf info iftop</code>

<code>Using metadata from Wed Aug </code><code>23</code> <code>00</code><code>:</code><code>36</code><code>:</code><code>04</code> <code>2017</code>

<code>可安裝的軟體包</code>

<code>名稱        : iftop</code>

<code>架構        : x86_64</code>

<code>時期        : </code><code>0</code>

<code>版本        : </code><code>1.0</code>

<code>釋出        : </code><code>0.14</code><code>.pre4.el7</code>

<code>大小        : </code><code>52</code> <code>k</code>

<code>倉庫        : epel</code>

<code>概要        : Command line tool that displays bandwidth usage on an </code><code>interface</code>

<code>URL         : http:</code><code>//www.ex-parrot.com/~pdw/iftop/</code>

<code>協定        : GPLv2+</code>

<code>描述        : iftop does </code><code>for</code> <code>network usage what top(</code><code>1</code><code>) does </code><code>for</code> <code>CPU usage. It listens to</code>

<code>            </code><code>: network traffic on a named </code><code>interface</code> <code>and displays a table of current bandwidth</code>

<code>            </code><code>: usage by pairs of hosts. Handy </code><code>for</code> <code>answering the question "why </code><code>is</code> <code>our ADSL link</code>

<code>            </code><code>: so slow?".</code>

2)安裝包

<code>[root@izpo45bh60h6bsz ~]</code><code># dnf install iftop</code>

3)擷取幫助

# man iftop 顯示主機接口之上的網絡帶寬使用情況

 iftop -h | [-nNpblBP] [-i interface] [-f filter code] [-F net/mask] [-G net6/mask6]

預設情況會反解主機名,-n選項或運作中使用r指令關閉dns反解

預設會顯示通過過濾器的所有IP包,IP包的方向是通過接口的方向

-F NETWORK 顯示給定網絡輸入或輸出的資料包 

忽略廣播資料包: not ether host  ff:ff:ff:ff:ff:ff

過濾僅顯示web資料包,排除:port http and not host webcache.example.com

使用者浪費了多少帶寬弄清楚網絡如此慢:icmp

    -h 擷取幫助

    -n 不從IP包中反解主機名

    -N 不反解端口号

    -p promise模式,流量不經過此接口也會統計

    -P 打開端口顯示

    -b bar開關

    -m #[km] 僅顯示由#指定的寬帶比例上限對應的資料包

    -i IFACE 指監聽接口

    -f filter code 過濾

    -F net/mask 過濾僅顯示什麼ip的資料包,包的方向由網絡邊界決定

    -c config_file 給出一個臨時配置檔案,預設 ~/.iftoprc

内建指令

S ,D , P ,p ,n ,N

<code>Host display:                          General:</code>

<code> </code><code>n - toggle DNS host resolution         P - pause display</code>

<code> </code><code>s - toggle show source host            h - toggle </code><code>this</code> <code>help display</code>

<code> </code><code>d - toggle show destination host       b - toggle bar graph display</code>

<code> </code><code>t - (revice,sent,two line,one line)            B - cycle bar graph average</code>

<code>                                        </code><code>T - toggle cumulative line totals</code>

<code>Port display:                           j/k - scroll display</code>

<code> </code><code>N - toggle service resolution          f - edit filter code</code>

<code> </code><code>S - toggle show source port            l - </code><code>set</code> <code>screen filter</code>

<code> </code><code>D - toggle show destination port       L - lin/log scales</code>

<code> </code><code>p - toggle port display                ! - shell command</code>

<code>                                        </code><code>q - quit</code>

<code>Sorting:</code>

<code> </code><code>1</code><code>/</code><code>2</code><code>/</code><code>3</code> <code>- sort by 1st/2nd/3rd column</code>

<code> </code><code>&lt; - sort by source name</code>

<code> </code><code>&gt; - sort by dest name</code>

<code> </code><code>o - freeze current order</code>

顯示注釋

<code>每個字段</code><code>10</code><code>秒平均流量顯示</code>

<code>foo.example.com  =&gt;  bar.example.com      1Kb  500b   100b</code>

<code>流量從 foo.example.com 到 bar.example.com</code>

<code>1Kb 前</code><code>2</code><code>秒資料被接收或發送的速率</code>

<code>500b 前</code><code>10</code><code>秒</code>

<code>100b 前</code><code>40</code><code>秒</code>

<code>過濾後的總傳輸流量</code>

<code>最近40s高峰流量</code>

<code>過去2s,10s,40s部傳輸速率</code>

<code></code>

本文轉自 lccnx 51CTO部落格,原文連結:http://blog.51cto.com/sonlich/1958550,如需轉載請自行聯系原作者

繼續閱讀