简介
tsar 是淘宝6年前开源的一款主机性能采集软件(开源地址是:https://github.com/alibaba/tsar/),可以说是运维人员性能分析的一把瑞士军刀。
目前大部分性能采集监控软件的架构都是client agent加server中心web页面展示这种架构,页面上能看性能曲线,能比对历史,能用于趋势判断等。开源的有Cacti,Zabbix等,商业软件的有QMonitor(无agent)。以及各大云计算公司自己的数据库运维产品。 在大规模服务器运维时这类产品能方便运维快速定位问题服务器和问题特征。
不过这并不妨碍tsar的作用。当针对一个具体的服务器进行问题诊断时,tsar也有自己独特的优势。比如说适合在命令行下分析性能问题的,或者主机死机(Hang)的场景,或者监控平台不正常的时候。
此外tsar是开源的,C语言编写,框架简单易懂,支持用户扩展功能。
tsar可以在主机后台以crontab任务运行(每分钟一次),也可以在命令行下运行查看历史数据,或者实时采集(live模式,最快每秒一次)。
本文主要分享一下tsar的安装、原理、以及实际使用案例。
安装部署介绍
tsar是用c语言编写的,下载代码编译安装即可。也可以编译代码生成一个rpm包安装。
$ git clone git://github.com/kongjian/tsar.git
$ cd tsar
$ make
# make install
安装后的文件介绍。
/etc/tsar/tsar.conf # tsar的主要配置文件。
/etc/cron.d/tsar # tsar的crond文件,由操作系统的crontab任务调用,默认每分钟一次
/etc/logrotate.d/tsar # tsar的性能采集数据(log)的生成规则设置,默认是每个月一个文件
/var/log/tsar.data* # tsar的性能采集数据(log)文件,非常小
/usr/local/tsar/modules # tsar里插件模块文件(*.so),定制的模块放在这里
Makefile
见Makefile
DIRS = modules src
all:
for i in $(DIRS); do make -C $$i; done
clean:
for i in $(DIRS); do cd $$i;make clean;cd ..; done
install: all
#mkdir for tsar
mkdir -p /usr/local/tsar/modules
mkdir -p /etc/tsar
mkdir -p /usr/local/man/man8/
#copy tsar shared so
cp modules/*.so /usr/local/tsar/modules
#copy bin file
cp src/tsar /usr/bin/tsar
#copy config file
cp conf/tsar.conf /etc/tsar/tsar.conf
cp conf/tsar.logrotate /etc/logrotate.d/tsar
cp conf/tsar.cron /etc/cron.d/tsar
#copy man file
cp conf/tsar.8 /usr/local/man/man8/
tsardevel:
mkdir -p /usr/local/tsar/devel
cp devel/mod_test.c /usr/local/tsar/devel/mod_test.c
cp devel/mod_test.conf /usr/local/tsar/devel/mod_test.conf
cp devel/tsar.h /usr/local/tsar/devel/tsar.h
cp devel/Makefile.test /usr/local/tsar/devel/Makefile.test
cp devel/tsardevel /usr/bin/tsardevel
uninstall:
#rm tsar
rm -rf /usr/local/tsar
rm -f /etc/logrotate.d/tsar
rm -f /etc/cron.d/tsar
rm -f /usr/local/man/man8/tsar.8
#rm tsar
rm -f /usr/bin/tsar
#rm tsardevel
rm -f /usr/bin/tsardevel
#backup configure file
if [ -f /etc/tsar/tsar.conf ]; then mv /etc/tsar/tsar.conf /etc/tsar/tsar.conf.rpmsave; fi
#backup the log data file
if [ -f /var/log/tsar.data ]; then mv /var/log/tsar.data /var/log/tsar.data.bak; fi
tags:
ctags -R
cscope -Rbq
tsar的调度细节
[mq@mqdba tsar]$ cat /etc/cron.d/tsar
# cron tsar collect once per minute
MAILTO=""
* * * * * root /usr/bin/tsar --cron >> /tmp/tsar.log 2>&1
HELP
使用还是很简单易懂的
$tsar --help
Usage: tsar [options]
Options:
-check display last record for alert
--check/-C display last record for alert.example:tsar --check / tsar --check --cpu --io
--cron/-c run in cron mode, output data to file
--interval/-i specify intervals numbers, in minutes if with --live, it is in seconds
--list/-L list enabled modules
--live/-l running print live mode, which module will print
--file/-f specify a filepath as input
--ndays/-n show the value for the past days (default: 1)
--date/-d show the value for the specify day(n or YYYYMMDD)
--merge/-m merge multiply item to one
--detail/-D do not conver data to K/M/G
--spec/-s show spec field data, tsar --cpu -s sys,util
--item/-I show spec item data, tsar --io -I sda
--help/-h help
Modules Enabled:
--cpu CPU share (user, system, interrupt, nice, & idle)
--mem Physical memory share (active, inactive, cached, free, wired, dirty)
--swap swap usage
--tcp TCP traffic (v4)
--udp UDP traffic (v4)
--traffic Net traffic statistics
--io Linux I/O performance
--pcsw Process (task) creation and context switch
--partition Disk and partition usage
--tcpx TCP connection data
--load System Run Queue and load average
只带日期不带其他参数的时候,显示的是指定日期的所有采集的summary字段。
#tsar --date 20150930
Time ---cpu-- -------mem------ ---tcp-- -----traffic---- --sda--- --sdb--- ---load-
Time util util ratio retran bytin bytout util util load1
30/09/15-00:05 57.35 62.69 0.11 0.00 2.3M 6.7M 22.75 34.09 37.68
30/09/15-00:10 61.22 62.78 0.13 0.01 1.9M 16.4M 23.24 24.75 34.25
30/09/15-00:15 62.93 62.82 0.11 0.01 2.1M 10.8M 23.83 21.86 21.41
30/09/15-00:20 58.31 62.85 0.16 0.01 1.9M 10.2M 21.46 21.19 17.14
30/09/15-00:25 56.25 62.88 0.23 0.01 1.8M 9.6M 20.51 21.66 30.48
30/09/15-00:30 59.22 62.90 0.11 0.01 2.2M 10.0M 34.38 23.24 23.06
30/09/15-00:35 57.72 62.89 0.09 0.01 2.2M 10.3M 34.91 20.77 27.65
30/09/15-00:40 56.63 62.91 0.13 0.01 2.2M 9.6M 36.05 19.34 17.15
30/09/15-00:45 57.49 62.92 0.16 0.01 2.2M 10.2M 33.78 20.62 23.62
30/09/15-00:50 56.13 62.94 0.09 0.00 2.1M 10.1M 33.77 19.24 20.60
30/09/15-00:55 56.48 62.95 0.05 0.02 2.1M 13.3M 34.13 20.23 17.17
30/09/15-01:00 54.11 62.94 0.08 0.01 2.1M 10.0M 32.94 18.41 27.64
30/09/15-01:05 54.83 62.92 0.13 0.01 2.5M 10.9M 33.96 19.91 22.50
30/09/15-01:10 60.25 62.98 0.13 0.01 2.1M 12.1M 34.82 20.57 20.58
30/09/15-01:15 62.58 63.03 0.09 0.02 2.1M 12.8M 33.29 20.88 23.63
30/09/15-01:20 63.97 63.04 0.16 0.02 2.4M 18.2M 33.00 19.74 26.18
30/09/15-01:25 63.02 62.96 0.07 0.01 3.0M 13.8M 32.53 27.91 24.34
30/09/15-01:30 60.53 63.00 0.09 0.01 2.1M 11.5M 33.48 26.12 23.54
30/09/15-01:35 55.07 62.98 0.13 0.00 2.1M 10.0M 33.81 20.44 23.33
Time ---cpu-- -------mem------ ---tcp-- -----traffic---- --sda--- --sdb--- ---load-
Time util util ratio retran bytin bytout util util load1
30/09/15-01:40 54.13 62.94 0.14 0.01 2.0M 9.5M 32.76 19.58 17.02
30/09/15-01:45 48.20 62.86 0.27 0.00 2.0M 7.1M 32.81 14.05 23.17
<省略...>
30/09/15-09:00 58.10 61.97 0.33 0.00 2.0M 7.4M 22.38 25.51 33.47
30/09/15-09:05 58.74 61.99 0.04 0.01 2.9M 12.1M 25.77 23.63 21.08
MAX 75.55 63.04 2.79 0.00 3.3M 21.1M 36.05 47.26 40.64
MEAN 54.38 62.08 0.16 0.01 2.1M 9.5M 26.99 20.75 20.77
MIN 43.21 59.17 0.11 0.00 1.6M 5.9M 16.52 13.74 11.67
备注:
1. 这些记录是从tsar的采集文件里读取的。文件默认位置在 /var/log/tsar.data。
2. 文件中采集的时间间隔是1分钟,tsar默认显示时间间隔是5分钟。
3. 默认展示cpu、memory、tcp、traffic、io、load等6个模块的summary字段。通常我们只需要关注cpu、memory、load、io模块
tsar采集的模块介绍
tsar配置文件里会配置采集那些模块,类型还是很多的,并且支持定制
$ cat /etc/tsar/tsar.conf |grep -v "#" |grep mod |grep on
mod_cpu on
mod_mem on
mod_swap on
mod_tcp on
mod_udp on
mod_traffic on
mod_io on
mod_pcsw on
mod_partition on
mod_tcpx on
mod_load on
output_stdio_mod mod_swap,mod_partition,mod_cpu,mod_mem,mod_lvs,mod_haproxy,mod_traffic,mod_squid,mod_load,mod_tcp,mod_udp,mod_tcpx,mod_apache,mod_pcsw,mod_io,mod_percpu
tsar cpu模块介绍
采集cpu利用率信息
调用方法:
$tsar --cpu --date -i 1
Time -----------------------cpu----------------------
Time user sys wait hirq sirq util
30/09/15-00:05 9.89 2.26 0.29 0.00 0.33 12.52
30/09/15-00:10 10.20 2.09 0.26 0.00 0.33 12.65
<.....>
Time -----------------------cpu----------------------
Time user sys wait hirq sirq util
30/09/15-08:00 3.00 1.83 0.73 0.00 0.27 5.13
30/09/15-08:05 4.03 1.91 0.72 0.00 0.27 6.22
30/09/15-08:10 3.38 1.49 0.09 0.00 0.19 5.08
30/09/15-08:15 3.30 1.62 0.09 0.00 0.20 5.14
30/09/15-08:20 3.18 1.68 0.14 0.00 0.20 5.07
30/09/15-08:25 3.08 1.38 0.12 0.00 0.18 4.65
30/09/15-08:30 3.18 1.49 0.09 0.00 0.21 4.89
30/09/15-08:35 3.46 1.60 0.17 0.00 0.21 5.29
30/09/15-08:40 4.26 2.39 1.47 0.00 0.39 7.06
30/09/15-08:45 2.25 6.87 52.05 0.00 0.23 9.36
30/09/15-08:50 3.70 2.44 21.92 0.00 0.33 6.49
30/09/15-08:55 3.10 1.81 0.14 0.00 0.24 5.16
30/09/15-09:00 2.49 1.59 0.12 0.00 0.20 4.30
30/09/15-09:05 3.14 1.97 0.29 0.00 0.25 5.37
30/09/15-09:10 3.12 1.86 0.14 0.00 0.25 5.25
30/09/15-09:15 3.58 1.71 0.18 0.00 0.21 5.51
30/09/15-09:20 2.98 1.86 0.21 0.00 0.24 5.09
MAX 15.18 6.87 52.05 0.00 0.47 16.66
MEAN 4.27 1.52 0.80 0.00 0.17 5.98
MIN 2.19 1.11 0.07 0.00 0.10 3.29
CPU模块取值来源
cpu模块的值取自于 /proc/stat 。
代码见:https://github.com/alibaba/tsar/blob/master/modules/mod_cpu.c#L22
数据来源取自 /proc/stat
$head -n 1 /proc/stat
cpu 10189101499 65317818 2526382190 52926047601 9177201059 363666 759388494 0 0
/proc/stat字段
字段说明
user: 自启动至今,进程处于用户态的运行时间之和,不包括nice值为负的进程。
nice: 自启动至今,nice值为负的进程所占用的CPU时间。
system: 自启动至今,进程处于内核态的运行时间之和。
idle: 自启动至今,除IO等待外的其他等待时间之和。
iowait: 自启动至今,IO等待时间之和。
irq: 自启动至今,硬中断的时间之和。
softirq: 自启动至今,软中断的时间之和。
steal_time:which is the time spent in other operating systems when running in a virtualized environment(since 2.6.11)
guest: which is the time spent running a virtual CPU for guest operating systems under the control of the Linux kernel(since 2.6.24)
备注:
linux下,cpu工作在用户态、内核态和空闲态。CPU利用率指CPU工作在非空闲态下的时间/CPU总的执行时间。 Intel平台的Jiffies的时间单位是1/100 秒,即一个ticks。CPU的利用率就是用户态+内核态的Jiffies除以总的Jiffies。
CPU total = user + nice + system + idle + iowait + irq + softirq + steal_time + guest
%user = user / total. 注意:在top里,%user = (user + nice)/ total!
Util = 100 - idle - iowait - steal
备注:
linux内核在每个时钟中断时(ticks)更新kernel_stat变量各个成员变量的值,/proc/stat文件的值是在程序读取时更新。所以,这个精度是一个ticks。 当一个ticks内发生多次进程调度的时候,计算的CPU利用率会不准。
tsar load模块介绍
采集主机load性能数据。
调用方法:
$tsar --load -i 1 --date 20150930
Time -------------------load-----------------
Time load1 load5 load15 runq plit
30/09/15-00:01 4.18 4.00 4.23 9.00 13.4K
30/09/15-00:02 4.31 4.09 4.24 6.00 13.4K
30/09/15-00:03 3.62 3.94 4.18 3.00 13.4K
......
Time -------------------load-----------------
Time load1 load5 load15 runq plit
30/09/15-08:34 1.04 1.20 1.35 2.00 13.4K
30/09/15-08:35 0.96 1.16 1.32 0.00 13.4K
30/09/15-08:36 1.18 1.16 1.31 3.00 13.4K
30/09/15-08:37 2.31 1.48 1.41 1.00 13.4K
30/09/15-08:38 2.95 1.80 1.53 1.00 13.4K
30/09/15-08:39 2.89 2.03 1.62 4.00 13.4K
30/09/15-08:40 2.40 2.05 1.66 7.00 13.4K
30/09/15-08:41 3.49 2.43 1.81 1.00 13.4K
30/09/15-08:42 467.48 123.64 42.74 15.00 13.5K
30/09/15-08:43 1.1K 346.44 122.36 2.00 15.4K
30/09/15-08:44 2.3K 825.90 300.89 2.00 15.9K
30/09/15-08:45 3.0K 1.3K 503.05 1.00 16.5K
30/09/15-08:46 3.7K 1.8K 729.76 1.00 17.2K
30/09/15-08:47 2.2K 1.8K 800.40 3.00 13.5K
30/09/15-08:48 830.90 1.5K 750.51 1.00 13.5K
30/09/15-08:49 306.11 1.2K 703.63 3.00 13.5K
30/09/15-08:50 113.74 998.76 659.73 7.00 13.5K
30/09/15-08:51 42.69 817.26 618.53 1.00 13.5K
30/09/15-08:52 16.81 668.84 579.93 2.00 13.5K
......
30/09/15-10:53 1.33 1.55 1.98 1.00 13.5K
30/09/15-10:54 3.56 2.18 2.16 3.00 13.6K
MAX 3.7K 1.8K 800.40 15.00 17.2K
MEAN 23.77 23.86 23.91 2.11 13.4K
MIN 0.48 0.84 0.89 0.00 13.4K
备注:
1. runq是当前正在运行以及等待调度的线程(包括进程)数目,plit是系统上所有的线程(包括进程)数目。
取值来源
load模块数据取值来自 /proc/loadavg
$cat /proc/loadavg
2.77 2.38 2.24 2/13870 62137
/proc/loadavg介绍
前三个字段分别是 1分钟,5分钟,15分钟内在CPU的run queue里状态为'R'的线程(nr_running)以及状态为'D'的线程(nr_uninterruptible,多为等待disk I/O返回)的平均数值。每隔5秒钟更新一次。
load 取值逻辑见linux源码
static long calc_load_fold_active(struct rq *this_rq)
{
long nr_active, delta = 0;
nr_active = this_rq->nr_running;
nr_active += (long) this_rq->nr_uninterruptible;
if (nr_active != this_rq->calc_load_active) {
delta = nr_active - this_rq->calc_load_active;
this_rq->calc_load_active = nr_active;
}
return delta;
}
第4个字段的‘/’前面是当前状态为'R'的调度实体数(进程或者线程);‘/’后面是当前系统上所有在运行的调度实体数(进程或者线程)。通常‘/’前面的数值小于或者等于所有CPU的个数(包括超线程)。但是当使用cgroup的时候,每个control group在每个cpu下都有一个run queue。所有这些run queue里的状态为‘R’的调度实体数(进程或者线程)就很有可能大大超过CPU的个数。
loadavg 取值逻辑见linux源码
static int loadavg_proc_show(struct seq_file *m, void *v)
{
unsigned long avnrun[3], nr_runnable = 0;
struct cpumask cpus_allowed;
int i;
rcu_read_lock();
if (task_in_nonroot_cpuacct(current) &&
in_noninit_pid_ns(current->nsproxy->pid_ns)) {
get_avenrun_from_tsk(current, avnrun, FIXED_1/200, 0);
cpumask_copy(&cpus_allowed, cpu_possible_mask);
if (task_subsys_state(current, cpuset_subsys_id)) {
memset(&cpus_allowed, 0, sizeof(cpus_allowed));
get_tsk_cpu_allowed(current, &cpus_allowed);
}
for_each_cpu_and(i, cpu_possible_mask, &cpus_allowed)
nr_runnable += task_ca_running(current, i);
} else {
get_avenrun(avnrun, FIXED_1/200, 0);
nr_runnable = nr_running();
}
rcu_read_unlock();
seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
nr_running(), nr_threads,
task_active_pid_ns(current)->last_pid);
return 0;
}
第5个字段是最近运行的进程的PID。不关注。
tsar io介绍
采集IO设备的性能数据。如IOPS及明细,读写延时,吞吐量及明细,各种利用率指标等。随着高版本linux的io性能数据更丰富,可以自己修改这个源码支持更多指标。
调用方法
tsar --io -i 1 --date 20150930
Time ------------------------------------------sda------------------------------------------- ------------------------------------------sdb-------------------------------------------
Time rrqms wrqms rs ws rsecs wsecs rqsize qusize await svctm util rrqms wrqms rs ws rsecs wsecs rqsize qusize await svctm util
30/09/15-08:36 0.00 0.00 0.23 661.73 2.47 3.7K 5.66 0.00 0.14 0.08 5.38 0.00 0.00 0.10 286.67 1.60 1.4K 4.97 0.00 0.15 0.02 0.69
30/09/15-08:37 0.00 0.00 0.27 597.27 2.60 3.2K 5.48 0.00 0.26 0.14 8.19 0.00 0.00 1.2K 39.8K 106.8K 159.5K 6.50 34.00 0.82 0.01 43.71
30/09/15-08:38 0.00 0.00 0.30 538.73 2.73 3.7K 7.11 0.00 0.12 0.08 4.41 0.00 0.00 404.92 8.6K 28.9K 35.0K 7.12 0.00 0.10 0.01 7.12
30/09/15-08:39 0.00 0.00 0.23 564.55 2.60 3.3K 5.90 0.00 0.15 0.08 4.72 0.00 0.00 358.30 23.4K 42.5K 93.8K 5.74 4.00 0.20 0.01 17.37
30/09/15-08:40 0.00 0.00 0.25 596.20 2.53 3.2K 5.57 0.00 0.13 0.07 4.39 0.00 0.00 953.23 13.8K 116.4K 55.4K 11.67 5.00 0.39 0.01 16.54
30/09/15-08:41 0.00 0.00 0.42 949.60 3.27 4.6K 4.99 0.00 0.28 0.20 19.16 0.00 0.00 1.3K 29.7K 84.2K 118.9K 6.57 29.00 0.94 0.01 41.83
30/09/15-08:42 0.00 0.00 0.82 470.07 4.20 6.9K 14.96 0.00 0.12 0.07 3.10 0.00 0.00 62.60 2.3K 4.3K 11.8K 6.94 0.00 0.10 0.01 1.94
30/09/15-08:43 0.00 0.00 0.25 170.02 1.27 1.8K 11.06 0.00 0.10 0.06 1.10 0.00 0.00 9.80 2.2K 697.53 9.7K 4.69 0.00 0.10 0.01 1.30
30/09/15-08:44 0.00 0.00 0.12 44.23 0.47 176.23 3.98 0.00 0.04 0.03 0.12 0.00 0.00 0.00 2.3K 0.00 9.3K 4.00 0.00 0.10 0.00 1.01
30/09/15-08:45 0.00 0.00 0.12 36.57 0.47 146.27 4.00 0.00 0.05 0.03 0.11 0.00 0.00 0.00 2.3K 0.00 9.1K 4.00 0.00 0.11 0.00 1.00
30/09/15-08:46 0.00 0.00 0.12 41.65 0.47 166.60 4.00 0.00 0.06 0.04 0.15 0.00 0.00 0.00 2.1K 0.00 8.6K 4.00 0.00 0.12 0.00 0.94
30/09/15-08:47 0.00 0.00 0.23 726.07 2.13 21.4K 30.12 0.00 0.24 0.09 6.20 0.00 0.00 249.00 11.1K 22.2K 57.2K 7.00 2.00 0.22 0.01 9.98
30/09/15-08:48 0.00 0.00 0.28 607.82 2.27 3.4K 5.72 0.00 0.15 0.08 4.89 0.00 0.00 990.83 20.0K 123.7K 80.2K 9.73 7.00 0.33 0.01 18.10
30/09/15-08:49 0.00 0.00 0.22 584.68 2.00 3.4K 5.97 0.00 0.09 0.06 3.48 0.00 0.00 0.12 310.57 1.87 1.5K 5.03 0.00 0.09 0.02 0.67
MAX 0.00 0.00 11.73 2.5K 5.7K 41.2K 30.12 0.00 0.30 0.22 33.08 0.00 0.00 1.7K 57.8K 183.5K 232.2K 71.18 34.00 0.86 0.04 49.59
MEAN 0.00 0.00 0.43 629.94 75.38 4.3K 7.08 0.00 0.13 0.07 5.37 0.00 0.00 25.26 1.0K 2.7K 4.7K 6.21 0.26 0.15 0.03 1.58
MIN 0.00 0.00 0.22 36.57 0.47 146.27 3.98 0.00 0.08 0.12 0.12 0.00 0.00 0.08 154.93 0.00 832.13 4.00 0.00 0.08 0.04 0.26
取值来源
io模块取值来自于 /proc/diskstats
The /proc/diskstats file displays the I/O statistics
of block devices. Each line contains the following 14
fields:
1 - major number
2 - minor mumber
3 - device name
4 - reads completed successfully
5 - reads merged
6 - sectors read
7 - time spent reading (ms)
8 - writes completed
9 - writes merged
10 - sectors written
11 - time spent writing (ms)
12 - I/Os currently in progress
13 - time spent doing I/Os (ms)
14 - weighted time spent doing I/Os (ms)
For more details refer to Documentation/iostats.txt
/proc/diskstats下面有所有设备的I/O 统计信息。这里取sda和sdb看看。
$cat /proc/diskstats |grep sd
8 0 sda 3520691 0 757033290 3066644 4542026312 0 69447173810 981637431 0 543419506 983648131
8 1 sda1 829 0 4634 35 1249375 0 2498762 7705 0 2061 7718
8 2 sda2 1604712 0 20439050 74339 420751463 0 3366011704 35597894 0 16718907 35574089
8 3 sda3 570 0 4554 41 8343234 0 66745872 145757 0 40426 145109
8 4 sda4 1666 0 25002 345 1276113 0 10208904 9146 0 2343 9472
8 5 sda5 437 0 3496 42 0 0 0 0 0 29 42
8 6 sda6 437 0 3496 24 0 0 0 0 0 24 24
8 7 sda7 437 0 3496 29 0 0 0 0 0 29 29
8 8 sda8 437 0 3496 44 0 0 0 0 0 30 43
8 9 sda9 1910990 0 736544658 2991736 4110406127 0 66001708568 945876929 0 528760899 947911436
8 16 sdb 90730629 2833 5678959669 15320033 1420007987 1336 23756373232 213152968 0 47262857 228099941
8 17 sdb1 90730367 2833 5678957573 15320026 1420007987 1336 23756373232 213152968 0 47262845 228099885
计算规则:
rrqms : 每秒进行merge的读次数。 delta(reads merged)/s
wrqms : 每秒进行merge的写次数。 delta(write merged)/s
rs : 每秒完成的读I/O次数。 delta(read io)/s
ws : 每秒完成的写I/O次数。 delta(write io)/s
rsecs : 每秒读K字节数。 delta(read sects)/2s
wsecs : 每秒写K字节数。 delta(write sects)/2s
rqsize: 平均每个IO的大小(KB) delta(read sects + write sects)/(2*delta(read io + write io))
qusize: 平均I/O队列长度 delta(I/O weighted time(ms)) /s/1000 ?
await : 平均等待时间(queue + service)
svctm : 平均service时间 delta(I/O time(ms))/delta(read io + write io)
util : 平均I/O利用率 100* delta(I/O time(ms))/s
备注:
1. await时间取决于服务时间(svctm)以及I/O队列的长度和I/O请求的模式。
2. 如果svctm接近await,说明I/O几乎没有等待;如果await>>svctm,说明I/O队列太长.
3. rsecs 和 wsecs 应该是tsar写错了,正确的应该是 rkbs 和 wkbs。
tsar memory介绍
采集内存相关信息。如free、cache内存、以及dirty内存。
调用方法
Time -------------------------------mem------------------------------
Time free used buff cach dirty total util ratio
08/10/15-15:33 33.0G 105.5G 1.2G 112.7G 4.3M 252.4G 41.80 0.00
08/10/15-15:34 33.0G 105.5G 1.2G 112.7G 3.9M 252.4G 41.81 0.00
08/10/15-15:35 33.0G 105.5G 1.2G 112.7G 4.2M 252.4G 41.81 0.00
08/10/15-15:36 33.0G 105.5G 1.2G 112.7G 9.0M 252.4G 41.80 0.01
08/10/15-15:37 33.0G 105.5G 1.2G 112.7G 6.1M 252.4G 41.81 0.00
08/10/15-15:38 32.9G 105.5G 1.2G 112.7G 6.3M 252.4G 41.81 0.00
08/10/15-15:39 32.9G 105.5G 1.2G 112.7G 8.2M 252.4G 41.81 0.01
08/10/15-15:40 32.9G 105.5G 1.2G 112.7G 6.9M 252.4G 41.80 0.00
08/10/15-15:41 32.9G 105.5G 1.2G 112.7G 10.9M 252.4G 41.80 0.01
08/10/15-15:42 32.9G 105.5G 1.2G 112.7G 6.8M 252.4G 41.80 0.00
08/10/15-15:43 32.9G 105.5G 1.2G 112.8G 4.4M 252.4G 41.81 0.00
08/10/15-15:44 32.9G 105.5G 1.2G 112.8G 7.8M 252.4G 41.81 0.01
08/10/15-15:45 32.8G 105.6G 1.2G 112.8G 3.6M 252.4G 41.84 0.00
08/10/15-15:46 32.8G 105.6G 1.2G 112.8G 10.4M 252.4G 41.84 0.01
08/10/15-15:47 32.9G 105.5G 1.2G 112.8G 6.4M 252.4G 41.80 0.00
08/10/15-15:48 32.9G 105.5G 1.2G 112.8G 2.8M 252.4G 41.79 0.00
MAX 35.3G 105.6G 1.2G 115.9G 1.6G 252.4G 41.80 1.05
MEAN 33.0G 104.5G 1.2G 113.6G 16.0M 252.4G 41.42 0.01
MIN 30.5G 104.2G 1.2G 111.5G 1.5M 252.4G 41.39 0.06
取值来源
memory模块取值来源于 /proc/meminfo
$cat /proc/meminfo
MemTotal: 264643104 kB
MemFree: 34469032 kB
Buffers: 1288124 kB
Cached: 118301044 kB
SwapCached: 0 kB
Active: 148336024 kB
Inactive: 69260548 kB
Active(anon): 97050840 kB
Inactive(anon): 1036500 kB
Active(file): 51285184 kB
Inactive(file): 68224048 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 8388576 kB
SwapFree: 8388576 kB
Dirty: 5384 kB
Writeback: 0 kB
AnonPages: 98008016 kB
Mapped: 213000 kB
Shmem: 80184 kB
Slab: 9366180 kB
SReclaimable: 9138488 kB
SUnreclaim: 227692 kB
KernelStack: 125472 kB
PageTables: 322168 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 140710128 kB
Committed_AS: 269839640 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 866092 kB
VmallocChunk: 34358747188 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 7852 kB
DirectMap2M: 3102720 kB
DirectMap1G: 265289728 kB
计算规则: used = total - free - buffer -cached tsar 里的used 跟 linux的free命令里 “-/+ buffers/cache“ 得到的used是一致的。 dirty ratio = 100 * dirty / (free + buffer + cache - mapped )
对比 free命令结果:
#free -m
total used free shared buffers cached
Mem: 193799 177697 16101 0 1304 91464
-/+ buffers/cache: 84928 108870
Swap: 8187 0 8187
第一行:从全局角度描述系统内存使用状况: used:已使用内存,包括cached的内容+应用程序使用的内存 free:完全未被使用的内存 shared:应用程序共享内存 buffers:缓存,主要用于目录方面、inode值等 cached:缓存,用于已打开的文件
第二行:从应用程序角度描述内存使用: used:表示-/+ buffers/cache 应用程序使用的内存大小,为系统used-缓存值(buffers+cached) free:表示-/+ buffers/cache 应用程序可使用的内存大小,为系统free+缓存值(buffers+cached)
案例分析
cpu\load 分析
case 1
Time -----------------------cpu---------------------- -------------------load-----------------
Time user sys wait hirq sirq util load1 load5 load15 runq plit
30/09/15-08:41 5.00 5.22 3.34 0.00 0.68 10.93 3.49 2.43 1.81 1.00 13.4K
30/09/15-08:42 2.79 24.76 15.70 0.00 0.24 27.83 467.48 123.64 42.74 15.00 13.5K
30/09/15-08:43 1.38 2.87 75.23 0.00 0.10 4.36 1.1K 346.44 122.36 2.00 15.4K
30/09/15-08:44 1.02 0.68 82.96 0.00 0.07 1.79 2.3K 825.90 300.89 2.00 15.9K
30/09/15-08:45 1.05 0.71 82.94 0.00 0.07 1.84 3.0K 1.3K 503.05 1.00 16.5K
30/09/15-08:46 1.09 0.84 81.57 0.00 0.08 2.02 3.7K 1.8K 729.76 1.00 17.2K
30/09/15-08:47 6.35 4.72 27.55 0.00 0.63 11.74 2.2K 1.8K 800.40 3.00 13.5K
30/09/15-08:48 4.96 2.60 0.19 0.00 0.41 7.99 830.90 1.5K 750.51 1.00 13.5K
30/09/15-08:49 2.92 1.61 0.10 0.00 0.24 4.78 306.11 1.2K 703.63 3.00 13.5K
MAX 27.37 24.76 82.96 0.00 0.98 28.93 3.7K 1.8K 800.40 15.00 17.2K
MEAN 4.18 1.66 0.68 0.00 0.20 6.06 21.93 22.01 22.05 2.11 13.4K
MIN 1.02 0.68 0.03 0.00 0.10 1.79 0.48 0.84 0.89 0.00 13.4K
备注:
1. user低,sys低,wait高,runq低,load1高。
2. load突然变高,但是runq 一直很低。说明load里增加的大部分都是状态为'D'的线程(包括进程),很有可能是在等待IO。cpu的iowait突然增加,更验证了这点。
case 2
Time -----------------------cpu---------------------- -------------------load-----------------
Time user sys wait hirq sirq util load1 load5 load15 runq plit
12/10/15-04:40 85.13 8.87 0.89 0.00 3.19 97.34 55.75 54.11 53.02 59.00 3.1K
12/10/15-04:45 85.03 8.14 1.60 0.00 3.01 96.33 49.46 52.07 52.39 41.00 3.1K
12/10/15-04:50 86.85 7.70 0.77 0.00 2.95 97.64 49.05 52.44 52.67 46.00 3.1K
12/10/15-04:55 86.45 8.29 0.72 0.00 3.23 98.11 58.16 55.81 54.10 41.00 3.1K
12/10/15-05:00 85.18 8.17 0.85 0.00 3.43 96.91 39.18 48.57 51.73 29.00 3.1K
12/10/15-05:05 86.41 8.03 0.61 0.00 3.06 97.64 51.50 50.92 51.95 39.00 3.1K
12/10/15-05:10 86.41 8.19 0.65 0.00 3.12 97.86 50.22 53.39 53.01 45.00 3.1K
12/10/15-05:15 84.87 7.90 1.06 0.00 2.96 95.87 41.98 47.58 50.70 39.00 3.1K
12/10/15-05:20 86.01 7.93 0.98 0.00 3.06 97.15 52.07 49.25 50.46 46.00 3.1K
12/10/15-05:25 86.02 8.34 0.52 0.00 3.00 97.49 45.44 48.80 50.18 49.00 3.1K
12/10/15-05:30 84.58 8.62 0.77 0.00 3.15 96.50 44.72 46.00 48.57 40.00 3.1K
12/10/15-05:35 85.11 8.00 1.24 0.00 3.10 96.35 46.54 47.36 48.58 47.00 3.1K
12/10/15-05:40 85.33 8.68 0.67 0.00 3.09 97.24 51.76 48.41 48.64 48.00 3.1K
12/10/15-05:45 85.09 7.90 1.16 0.00 2.97 96.10 44.91 47.96 48.42 26.00 3.1K
12/10/15-05:50 84.16 7.82 1.29 0.00 2.84 94.94 38.15 43.67 46.71 33.00 3.1K
12/10/15-05:55 84.15 8.58 1.39 0.00 3.07 95.93 53.11 47.58 47.51 42.00 3.1K
12/10/15-06:00 82.81 8.18 1.72 0.00 2.89 94.00 38.50 42.95 45.66 37.00 3.1K
12/10/15-06:05 85.21 8.39 0.83 0.00 2.98 96.72 47.79 45.93 46.26 40.00 3.1K
12/10/15-06:10 85.70 8.67 0.67 0.00 3.21 97.73 50.68 52.38 49.39 35.00 3.1K
备注:
1. user高,sys低,wait低,runq高,几乎跟load1相等。
2. runq的值说明load主要贡献是很多状态为'R'的进程。即有些进程比较耗CPU,很可能是mysql进程,而耗CPU的原因自然是sql性能不好。此种情形,实例iops指标也不低,主机IO压力也不低,只是还没有成为主要瓶颈。
case 3
$tsar --cpu --load -l -i 5
Time -----------------------cpu---------------------- -------------------load-----------------
Time user sys wait hirq sirq util load1 load5 load15 runq plit
12/10/15-21:30:22 10.35 24.64 1.48 0.00 0.72 35.74 449.14 449.75 440.42 5.00 16.8K
12/10/15-21:30:27 12.38 25.64 2.87 0.01 0.75 38.83 453.85 450.72 440.78 4.00 16.9K
12/10/15-21:30:32 10.97 24.85 2.40 0.00 0.65 36.55 457.55 451.53 441.10 0.00 16.8K
12/10/15-21:30:37 7.12 23.75 1.31 0.00 0.51 31.42 455.42 451.19 441.04 4.00 16.8K
12/10/15-21:30:42 7.62 23.84 1.27 0.00 0.57 32.11 458.83 451.97 441.35 4.00 16.9K
12/10/15-21:30:47 7.63 23.76 1.26 0.00 0.58 32.02 458.93 452.10 441.45 2.00 16.8K
12/10/15-21:30:52 9.62 25.06 1.26 0.00 0.54 35.31 462.22 452.90 441.76 3.00 16.8K
12/10/15-21:30:57 11.12 25.08 1.15 0.00 0.59 36.82 467.24 454.10 442.21 3.00 16.8K
12/10/15-21:31:02 10.75 24.65 1.21 0.00 0.57 36.04 471.63 455.22 442.64 0.00 16.8K
12/10/15-21:31:07 8.55 23.42 2.50 0.00 0.46 32.47 468.13 454.77 442.56 3.00 16.8K
12/10/15-21:31:12 9.20 23.60 1.08 0.00 0.53 33.36 465.88 454.53 442.55 2.00 16.8K
12/10/15-21:31:17 7.88 24.03 1.13 0.00 0.53 32.49 459.40 453.37 442.24 68.00 16.8K
12/10/15-21:31:22 8.55 23.90 1.18 0.00 0.60 33.10 451.84 451.90 441.82 132.00 16.8K
12/10/15-21:31:27 8.75 23.83 2.48 0.01 0.54 33.22 443.77 450.23 441.33 89.00 16.8K
12/10/15-21:31:32 8.79 23.67 5.43 0.00 0.45 32.99 437.30 448.78 440.91 105.00 16.8K
12/10/15-21:31:37 11.93 30.19 0.83 0.00 0.58 42.77 432.15 447.52 440.55 65.00 16.8K
12/10/15-21:31:42 12.34 25.57 0.90 0.00 0.60 38.59 428.38 446.48 440.25 79.00 16.8K
12/10/15-21:31:47 9.16 23.39 0.77 0.00 0.45 33.07 421.54 444.77 439.73 28.00 16.8K
12/10/15-21:31:52 8.69 24.90 0.89 0.00 0.58 34.20 418.05 443.66 439.40 3.00 16.8K
Time -----------------------cpu---------------------- -------------------load-----------------
Time user sys wait hirq sirq util load1 load5 load15 runq plit
12/10/15-21:31:57 7.10 23.52 0.73 0.00 0.49 31.20 411.48 441.87 438.84 3.00 16.8K
12/10/15-21:32:02 7.85 23.12 1.01 0.00 0.51 31.57 407.28 440.49 438.41 4.00 16.8K
12/10/15-21:32:07 8.20 24.71 1.03 0.00 0.63 33.57 399.33 438.29 437.71 6.00 16.8K
12/10/15-21:32:12 9.37 25.01 1.24 0.00 0.79 35.25 392.90 436.31 437.07 0.00 16.8K
12/10/15-21:32:17 7.98 23.34 1.18 0.00 0.71 32.12 386.74 434.32 436.42 3.00 16.8K
12/10/15-21:32:22 8.00 23.59 1.01 0.00 0.60 32.24 382.04 432.55 435.84 4.00 16.8K
12/10/15-21:32:27 7.98 24.03 2.08 0.01 0.54 32.61 376.51 430.57 435.18 5.00 16.8K
12/10/15-21:32:32 8.21 24.85 2.83 0.00 0.54 33.69 367.82 427.87 434.28 0.00 16.8K
12/10/15-21:32:37 7.58 23.30 0.75 0.00 0.49 31.43 360.63 425.38 433.44 1.00 16.8K
12/10/15-21:32:42 8.13 23.14 0.94 0.00 0.50 31.85 357.69 423.70 432.86 1.00 16.8K
12/10/15-21:32:47 8.00 23.30 0.82 0.00 0.51 31.86 356.04 422.26 432.34 0.00 16.8K
12/10/15-21:32:52 6.75 23.54 0.76 0.00 0.41 30.79 352.75 420.48 431.71 2.00 16.8K
12/10/15-21:32:57 7.64 23.53 0.85 0.00 0.47 31.70 346.92 418.14 430.90 0.00 16.8K
12/10/15-21:33:02 7.77 23.45 0.95 0.00 0.53 31.81 342.37 416.02 430.14 1.00 16.7K
12/10/15-21:33:07 7.16 23.59 0.82 0.00 0.43 31.22 339.77 414.26 429.49 2.00 16.7K
12/10/15-21:33:12 7.94 23.69 1.06 0.00 0.51 32.16 336.03 412.24 428.76 3.00 16.7K
12/10/15-21:33:17 7.43 23.89 1.03 0.00 0.49 31.84 334.10 410.58 428.13 2.00 16.7K
12/10/15-21:33:22 7.29 23.50 1.01 0.00 0.55 31.39 330.97 408.66 427.42 2.00 16.7K
12/10/15-21:33:27 7.75 23.83 2.11 0.00 0.53 32.13 330.01 407.17 426.84 3.00 16.7K
备注:
1. user不低,sys高,wait低,runq大部分时间低,load1高。wait一直很低说明load高主要原因不是io性能问题。主要原因很可能是个别mysql进程cpu利用率满了,可通过top命令查看具体进程。
3. 进一步查到该mysql实例进程,连接数和并发都很高,QPS,TPS很低,逻辑读高,说明平均单个SQL的逻辑读高,即sql性能不好。
4. 查看mysql会话状态
$mysqladmin -h127.0.0.1 -uroot -P XXXX -p******* processlist |awk -F'|' '{print $8}' |sort |uniq -c
3
2
1 init
1 Master has sent all binlog to slave; waiting for binlog to be updated
537 Sending data
1 Slave has read all relay log; waiting for the slave I/O thread to update it
1 State
2 update
1 Waiting for master to send event
61 Waiting for table level lock
1 Waiting on empty queue
大部分会话处于Sending data,但是实例的IOPS又不高。Sending data表示“选择和发送数据”,iops不高,说明大部分cpu耗费在选择数据上。后进一步看sql是myisam表,且走错索引。
Time -----------------------cpu---------------------- -----------------------mem---------------------- -------------------load-----------------
Time user sys wait hirq sirq util free used buff cach total util load1 load5 load15 runq plit
15/10/15-15:40:55 95.67 3.50 0.00 0.00 0.79 99.96 7.1G 67.1G 5.6G 109.5G 189.3G 35.46 979.35 896.64 563.64 994.00 6.8K
15/10/15-15:40:56 96.09 3.25 0.00 0.00 0.67 100.00 7.0G 67.1G 5.6G 109.5G 189.3G 35.47 979.35 896.64 563.64 964.00 6.8K
15/10/15-15:40:57 96.34 3.20 0.00 0.00 0.46 100.00 7.0G 67.1G 5.6G 109.5G 189.3G 35.47 979.35 896.64 563.64 966.00 6.8K
15/10/15-15:40:58 96.59 3.00 0.04 0.00 0.37 99.96 7.0G 67.1G 5.6G 109.5G 189.3G 35.47 979.35 896.64 563.64 908.00 6.8K
15/10/15-15:40:59 96.00 3.62 0.00 0.00 0.37 100.00 7.0G 67.1G 5.6G 109.5G 189.3G 35.47 979.35 896.64 563.64 667.00 6.8K
15/10/15-15:41:00 95.60 3.74 0.00 0.00 0.66 100.00 7.0G 67.1G 5.6G 109.5G 189.3G 35.46 986.05 899.40 566.33 1.0K 6.8K
15/10/15-15:41:01 94.51 4.74 0.00 0.00 0.71 100.00 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 986.05 899.40 566.33 307.00 6.8K
15/10/15-15:41:02 96.84 2.66 0.00 0.00 0.50 100.00 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 986.05 899.40 566.33 917.00 6.8K
15/10/15-15:41:03 95.93 3.62 0.00 0.00 0.42 99.96 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 986.05 899.40 566.33 910.00 6.8K
15/10/15-15:41:04 95.71 3.62 0.00 0.00 0.67 100.00 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 986.05 899.40 566.33 994.00 6.8K
15/10/15-15:41:05 96.30 3.20 0.00 0.00 0.50 100.00 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 999.42 903.61 569.48 926.00 6.8K
15/10/15-15:41:06 96.42 3.04 0.00 0.00 0.50 99.96 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 999.42 903.61 569.48 315.00 6.8K
15/10/15-15:41:07 95.88 3.54 0.00 0.00 0.58 100.00 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 999.42 903.61 569.48 950.00 6.8K
15/10/15-15:41:08 96.13 3.33 0.00 0.00 0.54 100.00 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 999.42 903.61 569.48 866.00 6.8K
15/10/15-15:41:09 95.92 3.33 0.00 0.00 0.67 99.96 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 999.42 903.61 569.48 871.00 6.8K
15/10/15-15:41:10 95.97 3.70 0.04 0.00 0.29 99.96 6.9G 67.1G 5.6G 109.6G 189.3G 35.47 994.74 904.23 571.47 901.00 6.8K
15/10/15-15:41:11 97.00 2.71 0.00 0.00 0.25 99.96 6.9G 67.1G 5.6G 109.6G 189.3G 35.47 994.74 904.23 571.47 799.00 6.8K
15/10/15-15:41:12 95.63 3.74 0.00 0.00 0.62 100.00 6.9G 67.1G 5.6G 109.6G 189.3G 35.47 994.74 904.23 571.47 905.00 6.8K
15/10/15-15:41:13 95.50 3.79 0.00 0.00 0.67 99.96 7.0G 67.1G 5.6G 109.6G 189.3G 35.47 994.74 904.23 571.47 924.00 6.8K
$tsar --io -l -i 1
Time ------------------------------------------sda------------------------------------------- ------------------------------------------sdb-------------------------------------------
Time rrqms wrqms rs ws rsecs wsecs rqsize qusize await svctm util rrqms wrqms rs ws rsecs wsecs rqsize qusize await svctm util
15/10/15-15:42:32 0.00 312.00 2.00 395.00 8.00 2.9K 7.39 0.00 0.02 0.02 0.80 0.00 258.00 455.00 49.00 7.1K 1.2K 16.90 0.00 0.15 0.14 7.10
15/10/15-15:42:33 0.00 557.00 5.00 707.00 68.00 6.9K 10.02 0.00 0.19 0.07 5.00 0.00 307.00 478.00 75.00 7.4K 1.8K 17.11 0.00 0.14 0.13 7.40
15/10/15-15:42:34 0.00 194.00 0.00 338.00 0.00 4.5K 13.53 0.00 0.15 0.14 4.70 0.00 324.00 812.00 96.00 12.7K 2.4K 17.06 0.00 0.17 0.16 14.50
15/10/15-15:42:35 0.00 207.00 0.00 331.00 0.00 2.6K 8.16 0.00 0.07 0.06 2.10 0.00 1.1K 735.00 99.00 11.5K 5.2K 20.44 0.00 0.13 0.12 9.90
15/10/15-15:42:36 0.00 272.00 0.00 300.00 0.00 6.4K 21.80 0.00 0.13 0.12 3.50 0.00 359.00 1.1K 130.00 17.3K 3.0K 16.84 0.00 0.15 0.13 16.10
15/10/15-15:42:37 0.00 208.00 0.00 82.00 0.00 3.7K 46.68 0.00 0.10 0.10 0.80 0.00 25.00 567.00 3.00 8.9K 112.00 16.11 0.00 0.13 0.13 7.30
15/10/15-15:42:38 0.00 164.00 0.00 201.00 0.00 5.3K 27.22 0.00 0.27 0.08 1.70 0.00 0.00 1.1K 0.00 17.4K 0.00 16.00 0.00 0.11 0.11 12.40
15/10/15-15:42:39 0.00 185.00 1.00 310.00 4.00 4.3K 14.24 0.00 0.13 0.07 2.30 0.00 229.00 1.0K 112.00 15.8K 2.6K 16.75 0.00 0.13 0.11 12.40
15/10/15-15:42:40 0.00 423.00 3.00 735.00 20.00 10.8K 15.06 0.00 0.10 0.09 6.50 0.00 15.7K 420.00 853.00 6.6K 69.4K 61.11 0.00 0.27 0.10 12.70
15/10/15-15:42:41 0.00 327.00 3.00 565.00 12.00 10.2K 18.39 0.00 0.14 0.11 6.40 0.00 7.1K 251.00 376.00 3.9K 31.1K 57.19 0.00 0.27 0.11 6.90
15/10/15-15:42:42 0.00 411.00 2.00 567.00 8.00 5.3K 9.59 0.00 0.08 0.07 4.20 0.00 8.4K 203.00 416.00 3.2K 36.3K 65.30 0.00 0.25 0.12 7.40
15/10/15-15:42:43 0.00 333.00 0.00 381.00 0.00 3.9K 10.53 0.00 0.08 0.09 3.30 0.00 263.00 217.00 29.00 3.4K 1.2K 18.91 0.00 0.20 0.17 4.10
15/10/15-15:42:44 0.00 606.00 1.00 868.00 4.00 8.0K 9.42 0.00 0.05 0.04 3.80 0.00 326.00 159.00 151.00 2.5K 3.3K 19.24 0.00 0.11 0.10 3.10
15/10/15-15:42:45 0.00 524.00 1.00 524.00 4.00 4.3K 8.38 0.00 0.10 0.07 3.80 0.00 353.00 140.00 61.00 2.2K 1.8K 20.46 0.00 0.12 0.11 2.30
15/10/15-15:42:46 0.00 502.00 3.00 757.00 12.00 5.0K 6.77 0.00 0.07 0.07 5.00 0.00 256.00 151.00 30.00 2.4K 1.1K 19.73 0.00 0.15 0.14 2.50
15/10/15-15:42:47 0.00 331.00 0.00 482.00 0.00 7.3K 15.41 0.00 0.11 0.07 3.30 0.00 448.00 170.00 210.00 2.7K 4.2K 18.43 0.00 0.12 0.10 3.90
15/10/15-15:42:48 0.00 388.00 0.00 509.00 0.00 6.0K 11.98 0.00 0.05 0.05 2.40 0.00 212.00 152.00 133.00 2.4K 2.7K 18.22 0.00 0.11 0.09 2.70
15/10/15-15:42:49 0.00 288.00 0.00 379.00 0.00 4.6K 12.36 0.00 0.06 0.06 2.30 0.00 302.00 211.00 174.00 3.3K 3.6K 18.43 0.00 0.18 0.14 5.30
15/10/15-15:42:50 0.00 309.00 0.00 426.00 0.00 4.6K 11.08 0.00 0.10 0.08 3.30 0.00 100.00 215.00 39.00 3.4K 956.00 17.31 0.00 0.21 0.15 3.90
原因
个别进程CPU利用率高。
$top
top - 15:44:46 up 567 days, 4:46, 1 user, load average: 992.72, 947.54, 657.12
Tasks: 652 total, 6 running, 646 sleeping, 0 stopped, 0 zombie
Cpu(s): 95.5%us, 3.9%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.5%si, 0.0%st
Mem: 198450624k total, 191313912k used, 7136712k free, 5832120k buffers
Swap: 7995360k total, 6072k used, 7989288k free, 115038140k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13576 mysql 20 0 15.2g 3.0g 7684 S 2333.4 1.6 469:24.70 mysqld
99074 mysql 20 0 22.4g 9.6g 6076 R 32.7 5.1 156733:24 mysqld
107288 mysql 20 0 14.9g 2.9g 5916 S 31.1 1.5 119350:39 mysqld
88754 mysql 20 0 12.3g 2.5g 5676 S 30.4 1.3 167839:47 mysqld
case 4 mysql wait太多导致load高
Time -----------------------cpu---------------------- -----------------------mem---------------------- -------------------load-----------------
Time user sys wait hirq sirq util free used buff cach total util load1 load5 load15 runq plit
18/10/15-17:06 17.97 7.10 3.36 0.00 2.70 27.83 9.6G 101.5G 408.7M 77.7G 189.3G 53.65 6.84 7.67 8.36 2.00 9.3K
18/10/15-17:07 13.49 7.01 3.32 0.00 2.76 23.35 9.5G 101.6G 408.9M 77.7G 189.3G 53.69 7.23 7.65 8.31 4.00 9.4K
18/10/15-17:08 13.62 7.42 3.52 0.00 2.61 23.72 9.5G 101.5G 409.1M 77.8G 189.3G 53.65 6.39 7.35 8.17 3.00 9.3K
18/10/15-17:09 12.08 19.41 2.85 0.00 2.68 34.22 9.4G 101.7G 409.3M 77.8G 189.3G 53.71 434.05 126.44 48.81 6.00 9.5K
18/10/15-17:10 14.37 21.69 2.72 0.00 2.85 38.98 9.3G 101.6G 409.4M 77.9G 189.3G 53.70 613.36 233.46 90.44 8.00 9.5K
18/10/15-17:11 15.88 21.41 2.60 0.00 2.81 40.19 9.3G 101.6G 409.5M 78.0G 189.3G 53.70 672.23 319.67 129.04 15.00 9.5K
18/10/15-17:12 12.42 22.85 2.58 0.00 2.59 37.93 9.3G 101.6G 409.7M 78.0G 189.3G 53.66 705.14 393.42 166.33 4.00 9.5K
18/10/15-17:13 12.41 22.24 2.89 0.00 2.84 37.55 9.3G 101.5G 409.8M 78.1G 189.3G 53.64 717.12 453.18 201.06 12.00 9.5K
18/10/15-17:14 12.07 21.54 2.62 0.00 2.78 36.45 9.2G 101.5G 409.9M 78.1G 189.3G 53.63 684.75 491.10 229.82 6.00 9.5K
18/10/15-17:15 12.36 21.99 2.66 0.00 2.75 37.16 9.2G 101.5G 410.1M 78.2G 189.3G 53.63 702.07 531.68 260.16 9.00 9.5K
18/10/15-17:16 12.51 21.58 2.72 0.00 2.74 36.89 9.1G 101.5G 410.2M 78.3G 189.3G 53.63 713.26 566.24 289.05 11.00 9.5K
18/10/15-17:17 12.10 21.03 2.60 0.00 2.66 35.86 9.1G 101.5G 410.3M 78.3G 189.3G 53.63 705.55 590.34 314.66 5.00 9.5K
18/10/15-17:18 12.19 22.04 2.62 0.00 2.74 37.04 9.0G 101.5G 410.5M 78.4G 189.3G 53.61 717.65 614.94 340.38 11.00 9.5K
18/10/15-17:19 12.02 21.25 2.90 0.00 2.81 36.13 8.9G 101.5G 410.8M 78.4G 189.3G 53.62 721.52 634.53 364.28 8.00 9.5K
18/10/15-17:20 12.57 21.71 2.54 0.00 2.80 37.14 8.9G 101.5G 411.0M 78.5G 189.3G 53.61 703.17 645.52 385.00 7.00 9.5K
18/10/15-17:21 12.42 21.39 2.67 0.00 2.78 36.65 8.8G 101.5G 411.1M 78.6G 189.3G 53.61 707.94 656.89 405.18 17.00 9.5K
18/10/15-17:22 12.42 21.42 2.60 0.00 2.82 36.73 8.8G 101.5G 411.3M 78.6G 189.3G 53.61 711.24 667.33 424.54 8.00 9.5K
18/10/15-17:23 14.54 21.44 2.51 0.00 2.82 38.88 8.7G 101.5G 411.4M 78.7G 189.3G 53.61 709.74 675.46 442.56 26.00 9.5K
18/10/15-17:24 13.30 22.94 2.38 0.00 2.89 39.24 8.7G 101.5G 411.6M 78.7G 189.3G 53.62 715.34 683.19 459.78 14.00 9.5K
备注:
1. load飙高,runq 间歇性增加一点点(小于cpu的总数)。cpu的wait没有变化,且很低。sys忽然变高,user没有变化。推测是 有mysql进程 有某种等待(不是等待io)。
总结
tsar主要是将主机相关的各个性能数据查看集中在一个命令下,实际在生产环境大规模部署过,对主机性能几乎无影响(如果是自己扩展模块要测试一下)。一个月下来产生的性能数据也不过几十KB。运维可以在命令行下查看过去的历史数据。当然不足的是每个指标值最小粒度是1分钟(linux的crontab限制)。在问题突发时还可以现场实时采集(最小粒度是1秒),实在是运维不可多得的利器,建议配置在装机模板里。