Linux系统监控——dstat 工具的使用

官方对dstat的定义为:多功能系统资源统计生成工具。

在获取的信息上有点类似于top、free、iostat、vmstat等多个工具的合集,官方解释为vmstat、iostat、ifstat等工具的多功能替代品,且添加了许多额外的功能(Dstat is a versatile replacement for vmstat, iostat and ifstat. Dstat overcomes some of the limitations and adds some extra features.);其结果可以保持到csv文件,使用脚本或第三方工具对性能进行分析利用(如通过监控平台监控,也可以保持到数据库)。

在Centos 6.x系统上安装基本服务器即默认安装,而在其他操作系统可能需要手动安装。

e.g.

  • 监控CPU、内存、swap、磁盘使用率,并输出到csv。recordTime 是每条记录的间隔时间,以 秒 为单位。recordNum 是记录数。
$ dstat -tcms --freespace --disk-util --output /home/TempFold/status.csv recordTime recordNum

此处的输出是追加模式。

  • 找出占用资源最高的进程和用户
    --top-(io|bio|cpu|cputime|cputime-avg|mem) 通过这几个选项,可以看到具体是那个用户那个进程占用了相关系统资源,对系统调优非常有效。如查看当前占用I/O、cpu、内存等最高的进程信息可以使用
$ dstat --top-mem --top-io --top-cpu

部分dstat的插件

  • --disk-util :显示某一时间磁盘的忙碌状况
  • --freespace :显示当前磁盘空间使用率
  • --proc-count :显示正在运行的程序数量
  • --top-bio :指出块I/O最大的进程
  • --top-cpu :图形化显示CPU占用最大的进程
  • --top-io :显示正常I/O最大的进程
  • --top-mem :显示占用最多内存的进程

查看:

$ dstat --list

internal:
	aio, cpu, cpu24, disk, disk24, disk24old, epoch, fs, int, int24, io, ipc, load, lock, mem, net, page, page24, proc, raw, socket, swap, swapold, 
	sys, tcp, time, udp, unix, vm

/usr/share/dstat:
	battery, battery-remain, cpufreq, dbus, disk-util, fan, freespace, gpfs, gpfs-ops, helloworld, innodb-buffer, innodb-io, innodb-ops, lustre, 
	memcache-hits, mysql-io, mysql-keys, mysql5-cmds, mysql5-conn, mysql5-io, mysql5-keys, net-packets, nfs3, nfs3-ops, nfsd3, nfsd3-ops, ntp, postfix, 
	power, proc-count, rpc, rpcd, sendmail, snooze, thermal, top-bio, top-cpu, top-cputime, top-cputime-avg, top-io, top-latency, top-latency-avg, 
	top-mem, top-oom, utmp, vm-memctl, vmk-hba, vmk-int, vmk-nic, vz-cpu, vz-io, vz-ubc, wifi

参考:
http://www.cnblogs.com/vincent-hv/p/3358194.html
http://linux.cn/article-3215-1.html
http://linux.die.net/man/1/dstat

dstat完整参数

Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics
Dstat options:
  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total

  -d, --disk             enable disk stats
     -D total,hda           include hda and total

  -g, --page             enable page stats,分页统计

  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2

  -l, --load             enable load stats

  -m, --mem              enable memory stats

  -n, --net              enable network stats
     -N eth1,total          include eth1 and total

  -p, --proc             enable process stats

  -r, --io               enable io stats (I/O requests completed)

  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total

  -t, --time             enable time/date output

  -T, --epoch            enable time counter (seconds since epoch)

  -y, --sys              enable system stats

  --aio                  enable aio stats

  --fs, --filesystem     enable fs stats,统计文件打开文件数和inodes数
  
  --ipc                  enable ipc stats

  --lock                 enable lock stats

  --raw                  enable raw stats

  --socket               enable socket stats

  --tcp                  enable tcp stats

  --udp                  enable udp stats

  --unix                 enable unix stats

  --vm                   enable vm stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total

  --bw, --blackonwhite   change colors for white background terminal
  --float                force float values on screen
  --integer              force integer values on screen
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers 关闭重复显示的标题
  --noupdate             disable intermediate updates
  --output file          write CSV output to file

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)

dstat插件

While anyone can create their own dstat plugins (and contribute them) dstat ships with a number of plugins already that extend its capabilities greatly.

Here is an overview of the plugins dstat ships with:

参数 含义
--battery battery in percentage (needs ACPI)
--battery-remain battery remaining in hours, minutes (needs ACPI)
--cpufreq CPU frequency in percentage (needs ACPI)
--dbus number of dbus connections (needs python-dbus)
--disk-util 硬盘使用百分率。per disk utilization in percentage
--fan fan speed (needs ACPI)
--freespace 每个硬盘使用情况。per filesystem disk usage
--gpfs GPFS read/write I/O (needs mmpmon)
--gpfs-ops GPFS filesystem operations (needs mmpmon)
--helloworld Hello world example dstat plugin
--innodb-buffer show innodb buffer stats
--innodb-io show innodb I/O stats
--innodb-ops show innodb operations counters
--lustre show lustre I/O throughput
--memcache-hits show the number of hits and misses from memcache (needs the memcache module)
--mysql5-cmds show the MySQL5 command stats
--mysql5-conn show the MySQL5 connection stats
--mysql5-io show the MySQL5 I/O stats
--mysql5-keys show the MySQL5 keys stats
--mysql-io show the MySQL I/O stats
--mysql-keys show the MySQL keys stats
--net-packets show the number of packets received and transmitted
--nfs3 show NFS v3 client operations
--nfs3-ops show extended NFS v3 client operations
--nfsd3 show NFS v3 server operations
--nfsd3-ops show extended NFS v3 server operations
--ntp show NTP time from an NTP server
--postfix show postfix queue sizes (needs postfix)
--power show power usage
--proc-count show total number of processes
--rpc show RPC client calls stats
--rpcd show RPC server calls stats
--sendmail show sendmail queue size (needs sendmail)
--snooze show number of ticks per second
--test show test plugin output
--thermal system temperature sensors
--top-bio show most expensive block I/O process
--top-cpu show most expensive CPU process
--top-cputime show process using the most CPU time (in ms)
--top-cputime-avg show process with the highest average timeslice (in ms)
--top-io show most expensive I/O process
--top-latency show process with highest total latency (in ms)
--top-latency-avg show process with the highest average latency (in ms)
--top-mem show process using the most memory
--top-oom show process that will be killed by OOM the first
--utmp show number of utmp connections (needs python-utmp)
--vmk-hba show VMware ESX kernel vmhba stats
--vmk-int show VMware ESX kernel interrupt stats
--vmk-nic show VMware ESX kernel port stats
--vm-memctl show ballooning status inside VMware guests
--vz-io show CPU usage per OpenVZ guest
--vz-ubc show OpenVZ user beancounters
--wifi wireless link quality and signal to noise ratio
posted @ 2014-12-26 15:09  Damian Zhou  阅读(1569)  评论(0编辑  收藏  举报