解析和可视化iostat输出
iostat-tool的Python项目详细描述
iostat工具
分析并可视化iostat输出
要求
- Python=3.4
- iostat工具使用asyncio监视iostat的输出
- Matplotlib
- 仅支持Linux的iostat输出
iostat
命令需要-t
参数来获取时间戳,建议使用-ymxt 1
参数
$ man iostat -t Print the timefor each report displayed. The timestamp format may depend on the value of the S_TIME_FORMAT environment variable (see below).
如何安装
对于用户
$ pip install iostat-tool
对于开发者
创建virtualenv以安装iostat-tool
。
$ mkdir virtualenvs $ virtualenv -p python3 virtualenvs/venv $ source virtualenvs/venv/bin/activate (venv) $
从存储库安装iostat-tool
包。
(venv) $ git clone https://github.com/t2y/iostat-tool.git (venv) $ cd iostat-tool (venv) $ python setup.py develop
基本cli选项
确认iostat-cli
按如下方式工作。
(venv) $ iostat-cli --help usage: iostat-cli [-h][--backend BACKEND][--data DATA][--fig-output FIGOUTPUT][--fig-size FIGSIZE][--output OUTPUT][--disks DISKS [DISKS ...]][--since SINCE][--until UNTIL][-v][--version]{csv,monitor,plot} ... positional arguments: {csv,monitor,plot} optional arguments: -h, --help show this help message and exit --backend BACKEND set backend for matplotlib, use TkAgg to monitor in the foreground --data DATA set path to iostat output file --fig-output FIGOUTPUT set path to save graph --fig-size FIGSIZE set figure size --output OUTPUT set path to save output of iostat --disks DISKS [DISKS ...]set disk name in iostat --since SINCE set since datetime, format: yyyymmddHHMISS --until UNTIL setuntil datetime, format: yyyymmddHHMISS -v, --verbose set verbose mode --version show program version
子命令
csv
从iostat的输出创建csv/tsv文件。
(venv) $ iostat-cli csv --help usage: iostat-cli csv [-h][--dialect {excel,excel-tab,unix}][--separator {comma,tab}] optional arguments: -h, --help show this help message and exit --dialect {excel,excel-tab,unix}set dialect for csv writer, default is excel --separator {comma,tab}set separator, default is comma
绘图
从iostat的输出创建matplotlib渲染的图像文件。
(venv) $ iostat-cli plot --help usage: iostat-cli plot [-h][--plot-type {plotter,scatter}][--subplots {io_rqm,iops,io_transfer,%util,avgrq-sz,avgqu-sz,await,svctm}[{io_rqm,iops,io_transfer,%util,avgrq-sz,avgqu-sz,await,svctm} ...]][--vlines VLINES [VLINES ...]] optional arguments: -h, --help show this help message and exit --plot-type {plotter,scatter}set plot type("plotter" by default) --subplots {io_rqm,iops,io_transfer,%util,avgrq-sz,avgqu-sz,await,svctm}[{io_rqm,iops,io_transfer,%util,avgrq-sz,avgqu-sz,await,svctm} ...]set subplots to show --vlines VLINES [VLINES ...]set vertical line, format: yyyymmddHHMISS --x-datetime-format X_DATETIME_FORMAT set datetime format for devices x-axis --title TITLE set title for graph --without-cpu don't plot CPU data --cpu-only plot only CPU data
监视器
监视并记录iostat
命令的输出。
(venv) $ iostat-cli monitor --help usage: iostat-cli monitor [-h][--iostat-args IOSTAT_ARGS][--max-queue-size MAX_QUEUE_SIZE] optional arguments: -h, --help show this help message and exit --iostat-args IOSTAT_ARGS set arguments for iostat --max-queue-size MAX_QUEUE_SIZE set queue size to read iostat output
如何使用
这是matplotlib渲染的示例图像。
已经有一个iostat.ouput作为数据文件
绘图
- 显示/dev/sda的所有子块和CPU平均值
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --disk sda --fig-output my-iostat.png plot (venv) $ file my-iostat.png my-iostat.png: PNG image data, 1800 x 1400, 8-bit/color RGBA, non-interlaced
- 显示/dev/sda和cpu平均值的任何子批
- 用
--subplots
过滤
io_rqm
和iops
- 用
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --disk sda --fig-output my-iostat.png \ plot --subplots io_rqm iops
- 显示任意日期时间范围
- 从2018-06-13 14:11:00开始过滤,
--since
- 使用
--until
筛选到2018-06-13 14:11:30
- 从2018-06-13 14:11:00开始过滤,
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --disk sda --fig-output my-iostat.png \ --since 20180613141100 --until 20180613141130 plot --subplots await svctm
- 在图形中显示垂直线
- 2018-06-13 14:11:10和2018-06-13 14:11:20与
--vlines
- 2018-06-13 14:11:10和2018-06-13 14:11:20与
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --disk sda --fig-output my-iostat.png \ --since 20180613141100 --until 20180613141130 plot --subplots await svctm --vlines 2018061314111020180613141120
- 仅显示CPU相关数据
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --disk sda --fig-output my-iostat.png \ plot --cpu-only
- 仅显示一个子块,不显示CPU信息
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --disk sda --fig-output my-iostat.png \ plot --subplots await --without-cpu
- 使用自定义标题生成图形
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --disk sda --fig-output my-iostat.png \ plot --title 'my custom test'
csv
- 输出2个csv文件(iostat_cpu.csv和iostat_devices.csv)
(venv) $ iostat-cli --data tests/fixtures/sample_iostat.output --output iostat.csv csv (venv) $ ls iostat_*.csv iostat_cpu.csv iostat_devices.csv (venv) $ head -n 3 iostat_*.csv ==> iostat_cpu.csv <== datetime,%user,%nice,%system,%iowait,%steal,%idle 2018-06-13 14:10:50,0.47,0.0,0.24,0.18,0.0,99.11 2018-06-13 14:10:51,3.07,0.0,0.66,0.09,0.0,96.18 ==> iostat_devices.csv <== datetime,device,rrqm/s,wrqm/s,r/s,w/s,rMB/s,wMB/s,avgrq-sz,avgqu-sz,await,r_await,w_await,svctm,%util 2018-06-13 14:10:50,sdd,0.07,45.88,1.57,0.59,0.08,0.18,246.55,0.26,121.04,1.28,436.94,2.07,0.45 2018-06-13 14:10:50,sdh,0.07,45.78,1.59,0.6,0.08,0.18,245.64,0.22,101.97,1.17,367.51,1.89,0.41
运行iostat并记录输出
- 监视iostat命令正在运行
- 几乎与
iostat -yxmt 1 | tee my-iostat.log
相同
- 几乎与
(venv) $ iostat-cli --output my-iostat.log --fig-output my-scatter.png monitor --iostat-args "-yxmt 1" ... 06/13/2018 10:11:07 PM avg-cpu: %user %nice %system %iowait %steal %idle 0.94 0.00 0.03 0.00 0.00 99.03 Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 06/18/2018 10:11:08 PM avg-cpu: %user %nice %system %iowait %steal %idle 0.16 0.00 0.06 0.00 0.00 99.78 ... (Ctrl + C)# stop to run iostat
(venv) $ file my-iostat.log my-scatter.png my-iostat.log: ASCII text my-scatter.png: PNG image data, 1800 x 1300, 8-bit/color RGBA, non-interlaced
注意:保存my-scatter.png
是IO stat终止时的实验功能,因此可能无法保存该图。