iotop是監視磁碟i/o使用狀況的top類工具,
可以針對程序和執行緒統計io的使用情況
對應的原始碼可以訪問這裡獲取:
[root@database1 ~]# yuminstall iotop
[root@database1 ~]# iotop --helpusage: /usr/sbin/iotop [options]
the thread is running (set using the ionice command).
controls:
left and right arrows to change the sorting column,
r to invert the sorting order,
o to toggle the --only option,
p to toggle the --processes option,
a to toggle the --accumulated option,
q to quit, any other key to force a refresh.
options:
--version show program'
s version number and exit
-h, --help show this help message and exit
-o, --only only show processes or threads actually doing i/o
-b, --batch non-interactive mode
-n num, --iter=num number of iterations before ending [infinite]
-d sec, --delay=sec delay between iterations [1
second]
-p pid, --pid=pid processes/threads to monitor [all]
-u user, --user=user users to monitor [all]
-p, --processes only show processes, not all threads
-a, --accumulated show accumulated i/o instead of bandwidth
-k, --kilobytes use kilobytes instead of a human friendly unit
-t, --time add a timestamp on each line (implies --batch)
-q, --quiet suppress some lines of header (implies --batch)
[root@yjweb ~]# iotop --versioniotop
0.6
1,只顯示有io操作的程序
[root@database1 ~]# iotop -o
說明:-o:只顯示有io操作的程序
2,顯示針對程序的統計
[root@database1 ~]# iotop -o -p
說明:預設是針對執行緒的統計,表頭是tid,
如果針對程序統計,表頭是pid
3,顯示啟動後累積的資料:
[root@database1 ~]# iotop -oa
說明:只看某乙個時間點的資料有時找不到消耗i/o最高的程序,
這時檢視累積的資料顯示更有效
4,監控指定pid的io使用:
[root@database1 ~]# iotop -p 26474
說明:-p 指定程序id
5,指定重新整理的間隔時間
[root@database1 ~]# iotop -o -d 2
說明:預設是1秒,
-d: 指定間隔的秒數,例子中是2秒重新整理一次
6,檢視指定使用者的io使用
[root@database1 ~]# iotop -o -a -u mysql
說明:-u: 指定使用者,當查詢mysql的io時很方便
6,非互動模式,批量處理 用來記錄日誌
[root@database1 ~]# iotop -boqtn3
說明:
-b: batch處理,不支援互動,常用來輸出日誌-q: quiet 只輸出一次表頭
-n:用來指定輸出迴圈次數:例子中我們用了3次
-t: 增加一列時間
-t和-q兩個引數只適用-b
如何輸出到檔案:
[root@database1 ~]# iotop -boqn3 > /root/iotop0319.txt 2>&1
o: 開啟/關閉 只顯示有io的程序/執行緒
p: 切換按程序和按執行緒的統計
a: 切換是否採用累積統計模式
q:退出
tid:執行緒id,按p可轉換程序pid
prio:優先順序
disk read:磁碟讀取速率
disk write:磁碟寫入速率
swapin:swap交換百分比
io>:io等待所占用百分比
command:執行緒/程序詳細資訊
用lsof
[root@database1 ~]# lsof -p 26474 | morecommand pid user fd type device size/off node name
mysqld
26474 mysql cwd dir 252,17
4096
18268161 /data/mysql/data
mysqld
26474 mysql rtd dir 252,1
4096
2 /mysqld
26474 mysql txt reg 252,1
11172576
1055031 /usr/sbin/mysqld
。。。
說明:lsof -p引數:列出指定程序id下開啟的檔案
說明:mysql在5.7版本給performance_schema.threads表增加了thread_os_id, 即系統執行緒字段低於5.7版本的mysql沒辦法根據作業系統的執行緒id找到sql
看例子:如果執行緒id是:19440
執行下面的sql即可:
selecta.name,
a.thread_id,
a.thread_os_id,
a.processlist_id,
a.type,
b.user
, b.host,
b.db,
b.command,
b.time,
b.state,
b.info
from
performance_schema.threads a
left
join
information_schema.processlist b
on a.processlist_id =
b.id
where a.type =
'foreground
'and a.thread_os_id =
19440
[root@yjweb ~]# cat /etc/redhat-releasecentos linux release 8.0.1905 (core)
centos8平台使用lsof
lsof,list open files 列出當前系統開啟檔案的工具。在linux環境下,任何事物都以檔案的形式存在,所以lsof通過檔案不僅僅可以訪問常規資料,還可以訪問網路連線和硬體 對應的原始碼可以訪問這裡獲取 1,檢視lsof所屬的包 root blog whereis lsof lsof ...
centos8平台使用ulimit做系統資源限制
1,ulimit 用於shell啟動程序所占用的資源,可用於修改系統資源限制 2,使用ulimit a 可以檢視當前系統的所有限制值 使用ulimit n 可以同時開啟的檔案數 設定使用者可以同時開啟的最大檔案數 max open files 新裝的linux預設只有1024,當作為併發訪問量大的伺...
centos8平台使用mpstat監控cpu
mpstat是 multiprocessor statistics的縮寫,是實時cpu監控工具。在多cpu系統裡,其不但能檢視所有cpu的平均狀況資訊,而且能夠檢視特定cpu的資訊 它的資料來自於 proc stat檔案 對應的原始碼可以訪問這裡獲取 1,檢視所屬的包 root blog where...