前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS7下系统分析与排障利器sysdig简单介绍

CentOS7下系统分析与排障利器sysdig简单介绍

作者头像
yuanfan2012
发布2020-07-24 15:25:31
2.5K0
发布2020-07-24 15:25:31
举报
文章被收录于专栏:WalkingCloud

sysdig是一个强大的开源工具,用于系统级别的分析,探测和排障,它的创建者在介绍它时称之为“strace+tcpdump+lsof+上面点缀着lua樱桃的绝妙酱汁”。抛开幽默不说,sysdig的最棒特性之一在于,它不仅能分析Linux系统的“现场”状态,也能将该状态保存为转储文件以供离线检查

sysdig - the definitive system and process troubleshooting tool sysdig is a tool for system troubleshooting, analysis and exploration. It can be used to capture, filter and decode system calls and other OS events. sysdig can be both used to inspect live systems, or to generate trace files that can be analyzed at a later stage. sysdig includes a powerul filtering language, has customizable output, and can be extended through Lua scripts, called chisels.

1、sysdig的安装

系统版本信息如下

代码语言:javascript
复制
[root@VM_Server ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@VM_Server ~]# uname -r
3.10.0-957.el7.x86_64
[root@VM_Server ~]# 

1)在线安装

先配置好yum源

代码语言:javascript
复制
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

sed -i "s/keepcache=0/keepcache=1/g" /etc/yum.conf
sed -i "s/gpgcheck=1/gpgcheck=0/g" /etc/yum.conf

脚本安装sysdig

代码语言:javascript
复制
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | bash

2)离线安装

代码语言:javascript
复制
 rpm -Uvh zlib-devel-1.2.7-18.el7.x86_64.rpm
 rpm -Uvh elfutils-*.rpm
 rpm -Uvh dkms-2.8.1-4.20200214git5ca628c.el7.noarch.rpm
 rpm -ivh sysdig-0.26.7-x86_64.rpm 

2、sysdig的使用

1、sysdig -cl (--list-chisels)列出可用的默认类目

默认有以下几类

代码语言:javascript
复制
[root@VM_Server ~]# sysdig -cl
Category: Application 应用
Category: CPU Usage  CPU使用量
Category: Errors 错误
Category: I/O
Category: Logs 日志
Category: Misc
Category: Net 网络
Category: Performance 性能
Category: Security 安全
Category: System State 系统状态
Category: Tracers
2、使用-i查看具体的信息
代码语言:javascript
复制
Use the -i flag to get detailed information about a specific chisel

[root@VM_Server ~]# sysdig -i topprocs_file

Category: I/O
-------------
topprocs_file   Top processes by R+W disk bytes

Shows the top processes in terms of total (in+out) bytes to disk. This chisel i
s compatible with containers using the sysdig -pc or -pcontainer argument, othe
rwise no container information will be shown.
Args:
(None)

3、用法举例

1)监控交互用户活动用法举例

作为系统管理员想要监控系统中交互的用户活动(如,用户在命令行输入了什么命令,以及用户去了什么目录),这时可以用spy_user “-z” (与“-w”一起使用)为记录文件启用压缩

-z, --compress Used with -w, enables compression for trace files

“-w ”保存sysdig记录到指定的文件

-w, --write=Write the captured events to.

-r, --read=Read the events from.

代码语言:javascript
复制
mkdir -p /log/sysdig/ 
 sysdig -z -w /log/sysdig/spy_users.sysdigcap.gz -c spy_users

例如yuanfan这个用户登录SSH后执行了如下命令

sysdig -c spy_users可以监控到这个用户的操作命令

-r, --read=Read the events from.

代码语言:javascript
复制
sysdig -r /log/sysdig/spy_users.sysdigcap.gz -c spy_users  

2)查看占用网络带宽最多的进程

代码语言:javascript
复制
sysdig -c topprocs_net

3)查看R+W读写量最大的文件

代码语言:javascript
复制
sysdig -c topfiles_bytes

4)查看CPU占用量最大的进程

代码语言:javascript
复制
sysdig -c topprocs_cpu 

4、总结

sysdig是一个非常强大的工具,本文篇幅有限,其它具体用法可以参考如下几个链接或者自行查阅官方文档

1)https://www.oschina.net/p/sysdig

2)http://www.361way.com/linux-sysdig/4912.html

3)https://github.com/draios/sysdig/wiki/sysdig-user-guide

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-07-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 WalkingCloud 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、sysdig的安装
    • 1)在线安装
      • 2)离线安装
      • 2、sysdig的使用
        • 1、sysdig -cl (--list-chisels)列出可用的默认类目
          • 2、使用-i查看具体的信息
      • 3、用法举例
        • 1)监控交互用户活动用法举例
          • 2)查看占用网络带宽最多的进程
            • 3)查看R+W读写量最大的文件
              • 4)查看CPU占用量最大的进程
              • 4、总结
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档