简介

    tsar是一个淘宝开发的服务器信息采集工具。

支持采集的信息如下:

  • 系统信息:如cpu、io、mem、tcp等
  • 应用数据:squid、haproxy、nginx等
  • 其他:自定义模块

具体介绍请参看以下文档:

  • tsar 官网
  • tsar工具使用
  • Linux系统性能监控工具介绍之-tsar

tsar 安装

安装准备

tsar 需要编译安装,安装前我们需要确保有编译环境

[root@base ~]# yum install -y cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc gcc-c++ make

安装

#下载源码包
[root@base ~]# wget -O tsar.zip https://github.com/alibaba/tsar/archive/master.zip --no-check-certificate
# 解压源码包
[root@base ~]# unzip tsar.zip && mv tsar-master tsar
[root@base ~]# cd tsar
# 编译安装
[root@base tsar]# make && make install

tsar使用

参考下面的帮助信息,完成对应的监控。

$tsar -h
Usage: tsar [options]
Options:-check         查看最后一次的采集数据--check/-C     查看最后一次tsar的提醒信息,如:tsar --check / tsar --check --cpu --io--cron/-c      使用crond模式来进行tsar监控--interval/-i  指明tsar的间隔时间,默认单位分钟,带上--live参数则单位是秒 --list/-L      列出启用的模块--live/-l      查看实时数据--file/-f      指定输入文件--ndays/-n     指定过去的数据天数,默认1天--date/-d      指定日期,YYYYMMDD或者n代表n天前--detail/-D    能够指定查看主要字段还是模块的所有字段--spec/-s      指定字段,tsar –cpu -s sys,utilModules Enabled:--cpu               列出cpu相关的监控计数--mem               物理内存的使用情况--swap              虚拟内存的使用情况--tcp               TCP 协议 IPV4的使用情况--udp               UDP 协议 IPV4的使用情况--traffic           网络传出的使用情况--io                Linux IO的情况--pcsw              进程和上下文切换--partition         磁盘使用情况--tcpx              TCP 连接相关的数据参数--load              系统负载情况

脚本导出CSV文件

注意:使用 Python 2.7.5 版本

#!/bin/python
# encoding=utf-8
# author: Onovo
import sys
import calendar
import time
import datetime
import os
import redef tsar(type='', date=''):"""tsar 导出概览信息type: 查询类型date: 查询日期(格式:yyyyMMdd)"""date = date if date != '' else (datetime.date.today() + datetime.timedelta(-1)).strftime("%Y%m%d")print "export " + date + ": " + type + " data ..."os.environ['type'] = '' if type == '' else '--' + typeos.environ['date'] = dateexportFileName = ''title = ''if type == '':exportFileName = "00 概述信息-"# 执行 `tsar -d 1` 查看修正titletitle = 'Time,cpu,mem,tcp-retran,traffic-bytin,traffic-bytout,sda,dm-0,dm-1,load\n'elif type.lower() == 'cpu':exportFileName = "01 CPU相关监控计数-"title = 'Time,user,sys,wait,hirq,sirq,util\n'elif type.lower() == 'mem':exportFileName = "02 物理内存使用情况-"title = 'Time,free,used,buff,cach,total,util\n'elif type.lower() == 'swap':exportFileName = "03 虚拟内存使用情况-"title = 'Time,swpin,swpout,total,util\n'elif type.lower() == 'tcp':exportFileName = "04 TCP(IPV4)使用情况-"title = 'Time,active,pasive,iseg,outseg,EstRes,AtmpFa,CurrEs,retran\n'elif type.lower() == 'udp':exportFileName = "05 UDP(IPV4)使用情况-"title = 'Time,idgm,odgm,noport,idmerr\n'elif type.lower() == 'traffic':exportFileName = "06 网络传输情况-"title = 'Time,bytin,bytout,pktin,pktout,pkterr,pktdrp\n'elif type.lower() == 'io':exportFileName = "07 IO使用情况-"disks = os.popen("tsar --io -d 1 | head -n 1 | sed 's/-//g' | sed 's/[ ][ ]*/ /g'").readline().strip().split(' ')diskNumber = len(disks)if diskNumber > 1:for index in range(1, diskNumber):if index == 1:title = title + ','title = title + disks[index] + ',,,,,,,,,,,,,,,,,'title = title + '\n'for index in range(1, diskNumber):if index == 1:title = title + 'Time,'title = title + 'rrqms,wrqms,%rrqm,%wrqm,rs,ws,rsecs,wsecs,rqsize,rarqsz,warqsz,qusize,await,rawait,wawait,svctm,util,'title = title + '\n'else:title = title + 'Time,rrqms,wrqms,%rrqm,%wrqm,rs,ws,rsecs,wsecs,rqsize,rarqsz,warqsz,qusize,await,rawait,wawait,svctm,util\n'elif type.lower() == 'pcsw':exportFileName = "08 进程和上下文切换情况-"title = 'Time,swch,proc\n'elif type.lower() == 'partition':exportFileName = "09 磁盘使用情况-"title = 'Time,bfree,bused,btotl,util,ifree,itotl,iutil,bfree,bused,btotl,util,ifree,itotl,iutil\n'elif type.lower() == 'tcpx':exportFileName = "10 TCP连接相关数据参数情况-"title = 'Time,recvq,sendq,est,twait,fwait1,fwait2,lisq,lising,lisove,cnest,ndrop,edrop,rdrop,pdrop,kdrop\n'elif type.lower() == 'load':exportFileName = "11 系统负载情况-"title = 'Time,load1,load5,load15,runq,plit\n'else:raise ValueError('参数 type 错误!')export = open("./inspection-logs/" + exportFileName + date + ".csv", "a+")# 添加表头if len(export.readlines()) < 1:export.write(title)# 获取数据lines = os.popen("tsar $type --date $date | grep -v Time | grep -v MAX | grep -v MEAN | grep -v MIN").readlines()for line in lines:if len(line) < 2:continuehard_info = re.sub('\s+', ' ', line.replace('\n', '').strip()).split(' ')hard_info[0] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.mktime(time.strptime(hard_info[0], "%d/%m/%y-%H:%M"))))export.write(','.join(hard_info) + '\n')export.close()def export_summarize_info(date=''):"""导出概述信息"""tsar('', date)def export_cpu_info(date=''):"""导出CPU相关监控计数"""tsar('cpu', date)def export_mem_info(date=''):"""导出物理内存使用情况"""tsar('mem', date)def export_swap_info(date=''):"""导出虚拟内存使用情况"""tsar('swap', date)def export_tcp_info(date=''):"""导出TCP(IPV4)使用情况"""tsar('tcp', date)def export_udp_info(date=''):"""导出UDP(IPV4)使用情况"""tsar('udp', date)def export_traffic_info(date=''):"""导出网络传输情况"""tsar('traffic', date)def export_io_info(date=''):"""导出IO使用情况"""tsar('io', date)def export_pcsw_info(date=''):"""导出进程和上下文切换情况"""tsar('pcsw', date)def export_partition_info(date=''):"""导出磁盘使用情况"""tsar('partition', date)def export_tcpx_info(date=''):"""导出TCP连接相关数据参数情况"""tsar('tcpx', date)def export_load_info(date=''):"""导出系统负载情况"""tsar('load', date)def export_all_info(date=''):"""导出所有信息"""export_summarize_info(date)export_cpu_info(date)export_mem_info(date)export_swap_info(date)export_tcp_info(date)export_udp_info(date)export_traffic_info(date)export_io_info(date)export_pcsw_info(date)export_partition_info(date)export_tcpx_info(date)export_load_info(date)if __name__ == "__main__":"""巡检主函数"""date = sys.argv[1]print '即将导出数据: ' + datestart_time = time.time()if len(date) == 6:# 数据切片取得年year = date[0:4]# 数据切片取得月month = date[4:6]date_now = int(time.strftime("%Y%m%d", time.localtime()))# 遍历指定月份的每一天for day in range(1, calendar.monthrange(int(year), int(month))[1] + 1):if day < 9:date = year + month + str(0) + str(day)else:date = year + month + str(day)day = day + 1# 判断结束日期if int(date) > date_now:continueexport_all_info(date)elif len(date) == 8:export_all_info(date)else:print '输入的日期格式错误,正确格式为 yyyyMM 或 yyyyMMdd'total_time = time.time() - start_timeprint '耗时:', time.strftime("%M分%S秒", time.localtime(total_time))

脚本调用方法

# 按日导出
[root@localhost ~]# ./tsar_check.py 20210221
# 按月导出
[root@localhost ~]# ./tsar_check.py 202102

Linux 监控工具 tsar相关推荐

  1. Linux 监控工具 tsar(转)

    转自:https://blog.csdn.net/u010945668/article/details/113904993 简介     tsar是一个淘宝开发的服务器信息采集工具. 支持采集的信息如 ...

  2. linux wireshark_4个好用的Linux监控工具

    作者 | Tate Galbraith 策划 | 万佳 本文介绍了作者常用的 4 个 Linux 监控工具,希望可以帮助读者提高生产力. 身为一个运维开发人员,如果你不知道眼下当前服务器底层操作系统中 ...

  3. [Linux实用工具]Linux监控工具munin的展示(Nginx)

    Munin的安装和配置可以参考第一篇文章: [Linux实用工具]Linux监控工具munin的安装和配置 http://www.cnblogs.com/rond/p/3757804.html Mun ...

  4. Linux:系统性能监控工具-tsar安装和使用

    在上家公司做性能压力测试时就用过tsar,但总结文档留在了内部,正好借着最近工作内容又用上了tsar,总结起来 目录 前言 tsar 介绍 总体架构 安装tasr tsar配置介绍 配置文件 定时任务 ...

  5. 4 个使用率非常高的 Linux 监控工具

    翻译 | 开源Linux 来源 | 整理自https://reurl.cc/g8Qq7p 下面是 Linux 下 4 个日常使用率非常高的监控工具,可以帮助我们准确快速的诊断系统问题. 1. ioto ...

  6. Linux监控工具Spotlight on Unix

    1.介绍 Spotlight on Unix是一款Linux系统运行状况的监控工具,可以安装在Windows下,监控Linux服务器的运行状况. 监控项目包括:CPU.内存.交换空间.虚拟内存等的使用 ...

  7. mysql linux 监控工具_细说linux服务器各种监控工具

    linux下面有很多强大的监控工具,各有各的优点,作为一个linux系统管理员,有必要知道这些命令的用法,结合自己的经验,写了点介绍,如对不足的地方,还请批评指正! yum install sysst ...

  8. linux监控工具等--zz

    本文转自http://www.os2ora.com Linux操作系统资源监控工具重点推荐 - collectl <!-- Post Body Copy --> Kaya 发表于 os2o ...

  9. Linux监控工具介绍系列——free`

    在Linux系统中,我们查看.监控系统内存使用情况,一般最常用的命令就是free.free命令其实非常简单,参数也非常简单,但是里面很多知识点未 必你都掌握了.下面总结一下我所了解的free命令.如有 ...

最新文章

  1. UDP通讯C++实现
  2. Inception GoogLeNet
  3. 我的Linux随笔目录
  4. 本周Github精选 | 这12个最新AI开源项目,你一定要收下
  5. php 获取每年的节假日,shell获取每年农历节日的日期
  6. 现代软件工程讲义 目录
  7. python守护进程_让Python脚本成为守护进程
  8. 微课|中学生可以这样学Python(5.8.1节):使用切片访问列表元素
  9. html 如何 创建目录,html - javascript:如何自动生成一篇文章的目录
  10. 机器学习模型 知乎_知乎CTO李大海:谢邀,来分享下内容社区的AI架构搭建与应用...
  11. MQTT 控制报文 - PUBLISH发布消息,PUBACK,PUBREC,PUBREL,PUBCOMP - 第6章
  12. 【图神经网络】Pytorch图神经网络库——PyG基础操作
  13. 1.urllib爬取数据
  14. 手把手教你ssm整合 超级详细
  15. qq空间显示手机型号android,手机QQ空间说说怎么显示手机型号
  16. 视频:忆童年有摇杆,《暗黑破坏神3》街机版演示
  17. RFID危化品管理系统解决方案
  18. linux gnu升级,GNU/Linux 让Ubuntu 系统版本升级
  19. C#和倍福PLC之间的通信
  20. C#之WinForms入门

热门文章

  1. TCP-UDP网络编程调试助手下载
  2. 世界数学史册上以***数学家命名的研究成果
  3. 数据分析——数据科学
  4. 一、MA(Moving Average)移动平均
  5. Docker 创建 Bamboo6.7.1 以及与 Crowd3.3.2 实现 SSO 单点登录
  6. 矩阵分析:矩阵序列,矩阵级数,矩阵函数,微积分,函数应用
  7. 正则表达式的学习总结
  8. 《炬丰科技-半导体工艺》湿法蚀刻工艺对铜及其合金蚀刻剂的评述
  9. 前端代码规范(个人约束)
  10. Mac 笔记本电脑扩展坞无法识别超过 2TB 容量外置存储的解决