tsar安装使用,好用的命令

tsar -L/--list 查看可用的模块列表
--modname 查看指定模块的运行状况,模块是指 tsar -L 列出来的名称 比如:tsar --cpu
[root@localhost ~]# tsar -L
tsar enable follow modules:
    cpu
    mem
    swap
    tcp
    udp
    traffic
    io
    pcsw
    partition
    tcpx
    load


-s/--spec 指定字段,tsar --cpu -s sys,util
查看多个模块的不同指定字段 
tsar --load  --cpu    -s runq,util 
Time           ---cpu-- ---load- 
Time             util     runq 
08/04/19-21:20  21.00    32.00 
08/04/19-21:25  14.51     9.00 
08/04/19-21:30   3.25     9.00 
08/04/19-21:35   3.16     7.00 
08/04/19-21:40   0.57    12.00 
08/04/19-21:45   0.76     9.00 
08/04/19-21:50   0.16     8.00 
08/04/19-21:55   0.15     7.00 
08/04/19-22:00   0.15    11.00 

-l/--live 查看实时数据
tsar -l 
Time              ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda--- --sdb---  ---load- 
Time                util     util   retran    bytin  bytout     util     util     load1 
08/04/19-21:27:18   0.27    30.66     0.00     4.0K    4.2K     0.00     0.00      0.13 
08/04/19-21:27:23   0.06    30.66     0.00   438.00    1.2K     0.00     0.00      0.12 
08/04/19-21:27:28   0.01    30.66     0.00   338.00  335.00     0.00     0.00      0.11 
08/04/19-21:27:33   0.05    30.66     0.00   176.00  377.00     0.00     0.00      0.10 
08/04/19-21:27:38   0.36    30.67     0.00     4.4K    5.1K     0.00     0.00      0.10 
08/04/19-21:27:43   0.13    30.67     0.00   242.00    1.1K     0.00     0.00      0.09 
08/04/19-21:27:48   0.42    30.66     0.00     4.0K    4.7K     0.00     0.00      0.08 
08/04/19-21:27:53   0.04    30.66     0.00   418.00  962.00     0.00     0.00      0.08 
08/04/19-21:27:58   0.09    30.66     0.00     1.0K    2.0K     0.00     0.02      0.07 
08/04/19-21:28:03   0.29    30.66     0.00   358.00    4.1K     0.00     0.00      0.06 
08/04/19-21:28:08   0.02    30.66     0.00    92.00  154.00     0.00     0.00      0.06 
08/04/19-21:28:13   0.11    30.66     0.00   117.00  803.00     0.00     0.00      0.05
 


查看 指定模块的实时信息
指定具体的监控对象,可以是磁盘,也可以是目录。
$tsar -l  --cpu
Time              -----------------------cpu---------------------- 
Time                user     sys    wait    hirq    sirq    util 
08/04/19-21:29:25   0.03    0.07    0.00    0.00    0.00    0.10 
08/04/19-21:29:30   0.01    0.02    0.00    0.00    0.00    0.02 
08/04/19-21:29:35   0.03    0.05    0.00    0.00    0.00    0.08 
08/04/19-21:29:40   0.01    0.01    0.00    0.00    0.00    0.02 
08/04/19-21:29:45   0.04    0.09    0.00    0.00    0.00    0.13 
08/04/19-21:29:50   0.01    0.01    0.00    0.00    0.00    0.02 
08/04/19-21:29:55   0.10    0.19    0.00    0.00    0.01    0.30 
08/04/19-21:30:00   0.01    0.02    0.00    0.00    0.00    0.02

-i/--interval 指定间隔,历史, 比如查看 sdb的性能数据,
$tsar --io -I sdb -l  
Time              ------------------------------------------sdb------------------------------------------- 
Time               rrqms   wrqms      rs      ws   rsecs   wsecs  rqsize  qusize   await   svctm    util 
08/04/19-21:59:01   0.00    0.00    0.00    2.8K    0.00   75.3K   26.77    0.00    0.05    0.02    7.00 
08/04/19-21:59:06   0.00    0.00    0.20    2.8K    0.80   75.7K   26.82    0.00    0.05    0.02    7.10 
08/04/19-21:59:11   0.00    0.00    0.00    2.8K    0.00   74.9K   26.83    0.00    0.05    0.02    6.84 
08/04/19-21:59:16   0.00    0.00    0.00    1.4K    0.00   37.9K   26.29    0.00    0.05    0.02    3.66

-d/--date 指定日期,YYYYMMDD或者n代表n天前
以下两个命令式一个意思
$tsar  --load  -d 20190409 
$tsar  --load  -d 1
Time           -------------------load-----------------
Time            load1   load5  load15    runq    plit
08/04/19-00:05   2.73    2.89    2.41    3.00    7.3K
08/04/19-00:10   1.40    1.94    2.11   41.00    7.2K
08/04/19-00:15   1.61    1.68    1.95    1.00    7.2K
08/04/19-00:20   1.83    1.82    1.93    4.00    7.2K
08/04/19-00:25   1.92    1.89    1.92    1.00    7.2K
08/04/19-00:30   1.11    1.48    1.75    5.00    7.2K

-D/--detail 能够指定查看主要字段还是模块的所有字段
命令行加上-D 与不加上D的区别
$tsar  --mem -D
Time           -----------------------mem---------------------- 
Time             free              used            buff         cach             total         util 
08/04/19-21:50 9325842432.00  86052364288.00  261754880.00  175354589184.00  270994550784.00   31.75 
08/04/19-21:55 9324318720.00  86052917248.00  262361088.00  175354953728.00  270994550784.00   31.75 
08/04/19-22:00 9352749056.00  86023622656.00  262938624.00  175355240448.00  270994550784.00   31.74 
08/04/19-22:05 9323311104.00  86051930112.00  263589888.00  175355719680.00  270994550784.00   31.75 
08/04/19-22:10 9320034304.00  86054137856.00  264204288.00  175356174336.00  270994550784.00   31.75 
08/04/19-22:15 9321422848.00  86051889152.00  264806400.00  175356432384.00  270994550784.00   31.75 
08/04/19-22:20 9316368384.00  86056013824.00  265383936.00  175356784640.00  270994550784.00   31.76 


$tsar  --mem
Time           -----------------------mem---------------------- 
Time             free    used    buff    cach   total    util 
08/04/19-21:50   8.7G   80.1G  249.6M  163.3G  252.4G   31.75 
08/04/19-21:55   8.7G   80.1G  250.2M  163.3G  252.4G   31.75 
08/04/19-22:00   8.7G   80.1G  250.8M  163.3G  252.4G   31.74 
08/04/19-22:05   8.7G   80.1G  251.4M  163.3G  252.4G   31.75 
08/04/19-22:10   8.7G   80.1G  252.0M  163.3G  252.4G   31.75

--partition 查看fstab指定挂在的系统目录的使用情况 ,-I 指定查看某个目录
$tsar --partition -I /u01 
Time           --------------/u01-------------- 
Time            bfree   bused   btotl    util 
19/09/14-15:20   1.9T    1.7T    3.8T   47.29 
19/09/14-15:25   1.9T    1.7T    3.8T   47.29 
19/09/14-15:30   1.9T    1.7T    3.8T   47.29 
19/09/14-15:35   1.9T    1.7T    3.8T   47.29 
19/09/14-15:40   1.9T    1.7T    3.8T   47.29 


常用命令
比较常用的是查看系统网络是否丢包
tsar --tcp -s retran

查看磁盘io情况
tsar --io -I sdb -s await,util,qusize,rs,ws

查看主机负载
tsar --load


[root@localhost ~]# tsar --tcp
Time           -------------------------------tcp------------------------------ 
Time           active  pasive    iseg  outseg  EstRes  AtmpFa  CurrEs  retran   
11/04/20-11:20   0.61    0.04    6.60   10.27    0.58    0.01  254.00    0.00   
11/04/20-11:25   0.54    0.05    6.81   10.37    0.50    0.01  257.00    0.00   
11/04/20-11:30   0.54    0.07    7.92   11.93    0.50    0.00  261.00    0.00   
11/04/20-11:35   0.70    0.05    6.98   10.36    0.66    0.01  257.00    0.39   
11/04/20-11:40   0.54    0.04    6.80   10.44    0.50    0.01  255.00    0.00   
11/04/20-11:45   0.54    0.04    5.96    9.67    0.50    0.00  255.00    0.24   
11/04/20-11:50   0.69    0.02    5.11    8.32    0.66    0.01  254.00    0.00   

tcp字段含义
active:主动打开的tcp连接数目
pasive:被动打开的tcp连接数目
iseg: 收到的tcp报文数目
outseg:发出的tcp报文数目
EstRes:Number of resets that have occurred at ESTABLISHED
AtmpFa:Number of failed connection 
attemptsCurrEs:当前状态为ESTABLISHED的tcp连接数
retran:系统的重传率


[root@admin ~]# tsar --tcpx
Time           -----------------------------------------------------------tcpx--------------------------------------------------------- 
Time            recvq   sendq     est   twait  fwait1  fwait2    lisq  lising  lisove   cnest   ndrop   edrop   rdrop   pdrop   kdrop   
11/04/20-11:50   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    0.00    0.00   
11/04/20-11:55   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    0.00    0.00   
11/04/20-12: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    0.00    0.00    0.00   
11/04/20-12:05   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    0.00    0.00   
11/04/20-12:10   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    0.00    0.00   
11/04/20-12:15   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    0.00    0.00   
11/04/20-12:20   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    0.00    0.00   


recvq sendq est twait fwait1 fwait2 lisq lising lisove cnest ndrop edrop rdrop pdrop kdrop
分别代表
tcprecvq tcpsendq tcpest tcptimewait tcpfinwait1 tcpfinwait2 tcplistenq tcplistenincq tcplistenover tcpnconnest tcpnconndrop tcpembdrop tcprexmitdrop tcppersistdrop tcpkadrop

安装nginx模块
tsar中可以添加很多的监控模块,这次添加nginx监控模块。
tsar的nginx扩展模块项目主页为:https://github.com/taobao/tsar-mod_nginx ,点击下载zip包。
[root@clsn6 tsar]#   unzip tsar-mod_nginx-master.zip 
[root@clsn6 tsar]#   tsardevel nginx
build:make
install:make install
uninstall:make uninstall
test:tsar --list or tsar --nginx --live -i 1

[root@clsn6 tsar]#   cp tsar-mod_nginx-master/mod_nginx.c nginx/
cp:是否覆盖"nginx/mod_nginx.c"? y

[root@clsn6 tsar]#   cd nginx/
[root@clsn6 nginx]# ls
Makefile  mod_nginx.c  mod_nginx.conf

[root@clsn6 nginx]# make && make install


测试
[root@clsn6 nginx]# service nginx start
正在启动 nginx:                                           [确定]
[root@clsn6 nginx]# tsar --nginx --live -i 1

nginx模块不能用问题的处理
此时通过使用tsar --nginx --live -i 1 命令查看,若出现都是横线。是因为nginx没有开启status统计页面 。
因为该工具统计的原理是通过获取status页面的输出结果,并对输出内容进行统计和计算得出的结果。而且其获取状态页的url默认是http://127.0.0.1/nginx_status ,所以在nginx上你必须有如下的配置:
location /nginx_status {
          stub_status on;
          access_log   off;
          allow 127.0.0.1;
          deny all;
        }
        
注:以上的url并非不能更改,可以修改环境变量实现。其自带的几个环境变量如下。
export NGX_TSAR_HOST=192.168.0.1
export NGX_TSAR_PORT=8080
export NGX_TSAR_SERVER_NAME=status.taobao.com
export NGX_TSAR_URI=/nginx_status

tsar刚安装完,还没有历史数据,想要check是否正常,执行tsar -l,查看是否有实时信息输出:
[root@centos_01 ~]# tsar -l -i 1
Time              ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda--- --sr0--- --dm-0-- --dm-1--  ---load- 
Time                util     util   retran    bytin  bytout     util     util     util     util     load1   
22/12/16-17:39:14   0.00    23.88     0.00   ------  ------     0.00     0.00     0.00     0.00      0.00   
22/12/16-17:39:15   0.00    23.88     0.00   ------  ------     0.00     0.00     0.00     0.00      0.00   
22/12/16-17:39:16   0.99    23.88     0.00   ------  ------     0.00     0.00     0.00     0.00      0.00   
22/12/16-17:39:17   0.00    23.88     0.00   ------  ------     0.00     0.00     0.00     0.00      0.00   
22/12/16-17:39:18   0.00    23.88     0.00   ------  ------     0.00     0.00     0.00     0.00      0.00   
22/12/16-17:39:19   1.00    23.88     0.00   ------  ------     0.00     0.00     0.00     0.00      0.00   

不指定 -i 1 默认为5秒显示一次

Modules Enabled:
    --cpu               列出cpu相关的监控计数
    --mem               物理内存的使用情况
    --swap              虚拟内存的使用情况
    --tcp               TCP 协议 IPV4的使用情况
    --udp               UDP 协议 IPV4的使用情况
    --traffic           网络传出的使用情况
    --io                Linux IO的情况
    --pcsw              进程和上下文切换
    --partition         磁盘使用情况
    --tcpx              TCP 连接相关的数据参数
--load              系统负载情况


cpu监控
[root@centos_01 ~]# tsar --cpu
Time           -----------------------cpu---------------------- 
Time             user     sys    wait    hirq    sirq    util   
22/12/16-14:45   0.06    0.13    0.00    0.00    0.01    0.19   
22/12/16-14:50   0.06    0.13    0.08    0.00    0.00    0.19   
22/12/16-14:55   0.04    0.09    0.00    0.00    0.00    0.13   
22/12/16-15:00   0.05    0.10    0.00    0.00    0.00    0.15   
22/12/16-15:05   0.05    0.15    0.01    0.00    0.00    0.20


内存和load情况
[root@centos_01 ~]# tsar --swap --load
Time           ---------------swap------------- -------------------load----------------- 
Time            swpin  swpout   total    util    load1   load5  load15    runq    plit   
22/12/16-14:45   0.00    0.00    2.0G    0.00     0.00    0.01    0.05    1.00  113.00   
22/12/16-14:50   0.00    0.00    2.0G    0.00     0.00    0.01    0.05    1.00  114.00   
22/12/16-14:55   0.00    0.00    2.0G    0.00     0.00    0.01    0.05    1.00  114.00   
22/12/16-15:00   0.00    0.00    2.0G    0.00     0.00    0.01    0.05    1.00  114.00   
22/12/16-15:05   0.00    0.00    2.0G    0.00     0.00    0.01    0.05    2.00  114.00   
22/12/16-15:10   0.00    0.00    2.0G    0.00     0.29    0.18    0.07    1.00  116.00   
22/12/16-15:15   0.00    0.00    2.0G    0.00     0.10    0.10    0.05    1.00  116.00   
22/12/16-15:20   0.00    0.00    2.0G    0.00     0.00    0.04    0.05    1.00  115.00 

内存使用情况
[root@centos_01 ~]# tsar --mem
Time           -----------------------mem---------------------- 
Time             free    used    buff    cach   total    util   
22/12/16-14:45  84.9M  267.8M    2.4M  621.5M  976.5M   27.42   
22/12/16-14:50  81.5M  268.4M    2.4M  624.1M  976.5M   27.49   
22/12/16-14:55  81.5M  268.4M    2.4M  624.1M  976.5M   27.49   
22/12/16-15:00  81.5M  268.4M    2.4M  624.2M  976.5M   27.48   
22/12/16-15:05  97.6M  268.4M    2.4M  608.1M  976.5M   27.49   
22/12/16-15:10 546.6M  217.1M    1.8M  211.1M  976.5M   22.23  


监控系统IO使用情况
查看历史记录
[root@centos_01 tsar-master]# tsar --io -I sda -w 30
Time           ------------------------------------------sda-------------------------------------------  
Time            rrqms   wrqms      rs      ws   rsecs   wsecs  rqsize  qusize   await   svctm    util    
23/12/16-16:50   0.00    0.03    0.00    0.16    0.00    0.84    5.31    0.00    1.37    0.87    0.01    
23/12/16-16:55   0.00    0.02    0.02    0.16    0.21    0.80    5.49    0.00    6.07    3.00    0.06    
23/12/16-17:00   0.00    0.03    0.02    0.29    0.11    2.72    9.21    0.00   10.50    3.72    0.11    
23/12/16-17:05   0.00    0.02    0.01    0.21    0.07    1.49    7.18    0.00    2.74    2.22    0.05    
23/12/16-17:10   0.00    0.01    0.00    0.14    0.00    0.69    5.00    0.00    1.90    1.83    0.03    
23/12/16-17:15   0.00    0.01    0.00    0.18    0.00    1.09    6.04    0.00    3.41    1.09    0.02    

MAX              0.00    0.03    0.00    0.29    0.21    2.72    9.21    0.00   10.50    3.72    0.11    
MEAN             0.00    0.02    0.01    0.20    0.08    1.36    6.58    0.00    4.92    2.37    0.05    
MIN              0.00    0.03    0.00    0.16    0.00    0.69    5.00    0.00    1.37    0.87    0.01 


查看实时记录,指定项 sda间隔为1s的实时显示
[root@centos_01 tsar-master]# tsar --io -I sda -l -i 1
Time              ------------------------------------------sda-------------------------------------------  
Time               rrqms   wrqms      rs      ws   rsecs   wsecs  rqsize  qusize   await   svctm    util    
23/12/16-17:15:22   0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    
23/12/16-17:15:23   0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    
23/12/16-17:15:24   0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    
23/12/16-17:15:25   0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    
23/12/16-17:15:26   0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    
23/12/16-17:15:27   0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00 


网络统计
#tsar --traffic -l -i 1
Time              ---------------------traffic-------------------- 
Time               bytin  bytout   pktin  pktout  pkterr  pktdrp   
23/12/16-17:19:22   7.6K    3.9K   61.00   43.00    0.00    0.00   
23/12/16-17:19:23   9.1K   54.7K   84.00   86.00    0.00    0.00   
23/12/16-17:19:24   2.3K  632.00   26.00    8.00    0.00    0.00   
23/12/16-17:19:25   3.9K    1.2K   47.00   14.00    0.00    0.00   
23/12/16-17:19:26   8.6K   54.4K   77.00   80.00    0.00    0.00


tsar检查告警信息
不带-m参数的
[root@centos_01 tsar-master]# tsar --check --partition
centos_01.dlync.com tsar partition:/:bfree=16085794816.0 partition:/:bused=2153136128.0 partition:/:btotl=18238930944.0 partition:/:util=12.8 partition:/:ifree=8866047.0 partition:/:itotl=8910848.0 partition:/:iutil=0.5 partition:/boot:bfree=870359040.0 partition:/boot:bused=192897024.0 partition:/boot:btotl=1063256064.0 partition:/boot:util=19.1 partition:/boot:ifree=523951.0 partition:/boot:itotl=524288.0 partition:/boot:iutil=0.1

带-m参数的(之所以带-m参数,是--partition有多个项,也可以看合并统计情况)
[root@centos_01 tsar-master]# tsar --check -m --partition
centos_01.dlync.com tsar partition:/:bfree=16956153856.0 partition:/:bused=2346033152.0 partition:/:btotl=19302187008.0 partition:/:util=13.2 partition:/:ifree=9389998.0 partition:/:itotl=9435136.0 partition:/:iutil=0.5


历史数据回溯
通过参数-d 1 可以查出一天前到现在的数据,-i 10 表示以每次10分钟作为采集显示。
[root@centos_01 tsar-master]# tsar -d 1 -i 10
Time           ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda--- --sr0--- --dm-0-- --dm-1--  ---load- 
Time             util     util   retran    bytin  bytout     util     util     util     util     load1   
22/12/16-14:50   0.19    27.49     0.00   ------  ------     0.08     0.00     0.08     0.00      0.00   
22/12/16-15:00   0.14    27.48     0.00   ------  ------     0.00     0.00     0.00     0.00      0.00   
22/12/16-15:10 ------    22.23     0.00   ------  ------   ------   ------   ------   ------      0.29   
22/12/16-15:20   0.46    22.63     0.00   ------  ------     0.11     0.00     0.11     0.00      0.00   
22/12/16-15:30   0.22    23.37     0.00   ------  ------     0.20     0.00     0.20     0.00      0.22   
22/12/16-15:40   0.23    23.40     0.00   ------  ------     0.01     0.00     0.01     0.00      0.00


例如查看啥时候关机或者重启的
tsar -d 1 -i 1   ##前一天的打印,每一分钟打印一次 (中断的时间为关机时间)
tsar -d 20171106 -i 1 ##打印20171106那天的记录,每分钟打印一次 (中断的时间为关机时间)

tsar --cpu   查看cpu
tsar --mem   查看内存
tsar --traffic   查看网络
-i 加时间 分钟  默认是5分钟
-d 加时间天  例:20171106  或者-d 1 表示前一天  不加-d表示当天

tsar只输出指定的参数
tsar --io -s await,util  ##-s参数

查看分析一分钟数据:
tsar --check --cpu  ##--check参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值