linuxidc@linuxidc:~/www.linuxidc.com/Linux公社$ dstat --output /tmp/stats.csv -a 2 5
--total-cpu-usage-- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai stl| read writ| recv send| in out | int csw
4 2 94 0 0| 209k 207k| 0 0 |4229B 25k| 130 653
20 7 73 0 0| 0 0 | 0 0 | 0 0 | 359 1001
15 5 80 0 0| 0 16k| 0 0 | 0 0 | 222 744
3 1 96 0 0| 0 0 | 0 0 | 0 0 | 93 270
1 2 96 1 0| 0 6144B| 0 0 | 0 0 | 80 243
这是csv文件的样例:
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社$ cat /tmp/stats.csv
"Dstat 0.7.3 CSV output"
"Author:","Dag Wieers <dag@wieers.com>",,,,"URL:","http://dag.wieers.com/home-made/dstat/"
"Host:","linuxidc",,,,"User:","linuxidc"
"Cmdline:","dstat --output /tmp/stats.csv -a 2 5",,,,"Date:","29 Dec 2018 17:11:59 CST"
"total cpu usage",,,,,"dsk/total",,"net/total",,"paging",,"system",
"usr","sys","idl","wai","stl","read","writ","recv","send","in","out","int","csw"
4.491,1.789,93.600,0.121,0,214501.354,212192.427,0,0,4229.474,25991.368,130.227,653.321
20.207,6.736,73.057,0,0,0,0,0,0,0,0,359,1000.500
15.464,4.639,79.897,0,0,0,16384,0,0,0,0,222,744
3.046,1.015,95.939,0,0,0,0,0,0,0,0,92.500,269.500
1.015,2.030,96.447,0.508,0,0,6144,0,0,0,0,79.500,242.500
什么是dstat?
如前所述,dstat是一个很好的工具,可用于查看系统性能的所有方面。 但是这个问题的另一个答案是它是一个Python脚本,如果你想看看它是如何工作的,你可以自由地阅读它。
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社$ which dstat
/usr/bin/dstat
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社$ file /usr/bin/dstat
/usr/bin/dstat: Python script, ASCII text executable
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社$ more /usr/bin/dstat | head -6
#!/usr/bin/env python2
### This program is free software; you can redistribute it and/or
### modify it under the terms of the GNU General Public License
### as published by the Free Software Foundation; either version 2
### of the License, or (at your option) any later version.