sysdig命令使用
kevin.Zhu 发布于:2022-1-18 17:51 分类:文摘 有 22 人浏览,获得评论 0 条
https://blog.csdn.net/cpongo3/article/details/98635616
一、安装
本篇主要介绍在centos下的用法安装和测试,后面也会提到在ubuntu类平台下的安装。其支持在centos6和centos7上安装,安装方法十分简洁:
1、centos下的安装
1.1一键安装
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash
上 面是一个shell 脚本,会识别常用的linux发行版本,并根据对应的版本配置源,最后是安装sysdig包。在redhat/centos上首先会配置的是epel 源 ,配置该源的目的是安装dkms包;然后会配置draios源,通过该源可以安装sysdig包。最后在装sysdig包之前还会先安装kernel- devel包。
1.2、分步安装
由于使用的源都是国外源,会出现安装比较慢的情况,所以使用一键安装失败时,可以使用分解步骤安装。在内网环境下的也可以将依赖包都下下来再安装。
#导入draios源
rpm –import https://s3.amazonaws.com/download.draios.com/DRAIOS-GPG-KEY.public
curl -s -o /etc/yum.repos.d/draios.repo http://download.draios.com/stable/rpm/draios.repo
#导入epel 源
rpm -i http://mirror.us.leaseweb.net/epel/6/x86_64/epel-release-6-8.noarch.rpm
#装包
yum -y install kernel-devel* dkms sysdig
sysdig依赖的两个包,一个是kernel-devel ,一个是dkms包,DKMS全称是Dynamic Kernel Module Support (动态内核模块支持),即在内核版本变动之后可以自动重新生成新驱动模块。想要了解的可以自行GOOGLE 。
2、ubuntu下的安装
curl -s https://s3.amazonaws.com/download.draios.com/DRAIOS-GPG-KEY.public | apt-key add –
curl -s -o /etc/apt/sources.list.d/draios.list
apt-get update
apt-get -y install linux-headers-$(uname -r)
apt-get -y install sysdig
windows、Mac OS及其他linux发行版的安装,可以参看官方安装文档。
二、常用用法
默认按上面的方法安装好以后,执行sysdig是会出错的。提示如下:
# sysdigUnable to load the drivererror opening device /dev/sysdig0. Make sure you have root credentials and that the sysdig-probe module is loaded.
所 以执行之前还需要使用/usr/bin/sysdig-probe-loader命令装载内核模块,该命令也是一个shell脚本,执行时会从aws s3上下载一个ko模块文件。不过我在linux测试主机上下载多次都未成功。查看该脚本文件后,发现其调用下载的地址 是:https://s3.amazonaws.com/download.draios.com/stable/sysdig-probe- binaries/sysdig-probe-0.6.0-x86_64-2.6.32-504.el6.x86_64-e065a96a1a7343d57e26548de23096e3.ko
注: 该ko文件的URL不用记,执行该脚本时会有相应的提示“Trying to download precompiled module from” ,而且不同的内核版本下的对应ko文件也是不同的。我这里的内核版本是2.6.32-504.el6 。下载完成后会存放在~/.sysdig 目录。
完成后再执行sysdig-probe-loader命令就可以执行sysdig命令了,而且开机后不会自动加载,所以在不使用的情况下,该包是对主机无影响的。
1、网络
查看占用网络带宽最多的进程:
sysdig -c topprocs_net
显示主机192.168.0.1的网络传输数据:
as binary:sysdig -s2000 -X -c echo_fds fd.cip=192.168.0.1
as ASCII:sysdig -s2000 -A -c echo_fds fd.cip=192.168.0.1
这里显示网络传输功能,实际效果和tcpdump抓包是一样的。而且其本身也支持sysdig -w dump.scap抓包保存(可以配置-X或-A使用),抓好包也支持sysdir -r dump.scap读取。
查看连接最多的服务器端口:
in terms of established connections:sysdig -c fdcount_by fd.sport “evt.type=accept”
in terms of total bytes:sysdig -c fdbytes_by fd.sport
查看客户端连接最多的ip:
in terms of established connectionssysdig -c fdcount_by fd.cip “evt.type=accept”
in terms of total bytessysdig -c fdbytes_by fd.cip
列出所有不是访问apache服务的访问连接:
sysdig -p”%proc.name %fd.name” “evt.type=accept and proc.name!=httpd”
2、硬盘 I/O
查看使用硬盘带宽最多的进程:
sysdig -c topprocs_file
列出使用大量文件描述符的进程
sysdig -c fdcount_by proc.name “fd.type=file”
See the top files in terms of read+write bytes
sysdig -c topfiles_bytes
Print the top files that apache has been reading from or writing to
sysdig -c topfiles_bytes proc.name=httpd
Basic opensnoop: snoop file opens as they occur
sysdig -p “%12user.name %6proc.pid %12proc.name %3fd.num %fd.typechar %fd.name” evt.type=open
See the top directories in terms of R+W disk activity
sysdig -c fdbytes_by fd.directory “fd.type=file”
See the top files in terms of R+W disk activity in the /tmp directory
sysdig -c fdbytes_by fd.filename “fd.directory=/tmp/”
Observe the I/O activity on all the files named ‘passwd’
sysdig -A -c echo_fds “fd.filename=passwd”
Display I/O activity by FD type
sysdig -c fdbytes_by fd.type
3、进程和CPU使用率
See the top processes in terms of CPU usage
sysdig -c topprocs_cpu
See the top processes for CPU 0
sysdig -c topprocs_cpu evt.cpu=0
Observe the standard output of a process
sysdig -s4096 -A -c stdout proc.name=cat
4、应用
查看机器所有的HTTP请求
sudo sysdig -s 2000 -A -c echo_fds fd.port=80 and evt.buffer contains GET
查看机器所有的SQL select查询
sudo sysdig -s 2000 -A -c echo_fds evt.buffer contains SELECT
See queries made via apache to an external MySQL server happening in real time
sysdig -s 2000 -A -c echo_fds fd.sip=192.168.30.5 and proc.name=apache2 and evt.buffer contains SELECT
5、性能和错误
See the files where most time has been spent
sysdig -c topfiles_time
See the files where apache spent most time
sysdig -c topfiles_time proc.name=httpd
See the top processes in terms of I/O errors
sysdig -c topprocs_errors
See the top files in terms of I/O errors
sysdig -c topfiles_errors
See all the failed disk I/O calls
sysdig fd.type=file and evt.failed=true
See all the failed file opens by httpd
sysdig “proc.name=httpd and evt.type=open and evt.failed=true”
See the system calls where most time has been spent
sysdig -c topscalls_time
See the top system calls returning errors
sysdig -c topscalls “evt.failed=true”
snoop failed file opens as they occur
sysdig -p “%12user.name %6proc.pid %12proc.name %3fd.num %fd.typechar %fd.name” evt.type=open and evt.failed=true
Print the file I/O calls that have a latency greater than 1ms:
sysdig -c fileslower 1
6、安全
Show the directories that the user “root” visits
sysdig -p”%evt.arg.path” “evt.type=chdir and user.name=root”
Observe ssh activity
sysdig -A -c echo_fds fd.name=/dev/pretmx and proc.name=sshd
Show every file open that happens in /etc
sysdig evt.type=open and fd.name contains /etc
Show the ID of all the login shells that have launched the “tar” command
sysdig -r file.scap -c list_login_shells tar
Show all the commands executed by the login shell with the given ID
sysdig -r trace.scap.gz -c spy_users proc.loginshellid=5459
7、容器
查看机器上运行的容器列表及其资源使用情况
sudo csysdig -vcontainers
查看容器上下文的进程列表
sudo csysdig -pc
查看运行在wordpress1容器里CPU的使用率
sudo sysdig -pc -c topprocs_cpu container.name=wordpress1
查看运行在wordpress1容器里网络带宽的使用率
sudo sysdig -pc -c topprocs_net container.name=wordpress1
查看在wordpress1容器里使用网络带宽最多的进程
sudo sysdig -pc -c topprocs_net container.name=wordpress1
查看在wordpress1 容器里占用 I/O 字节最多的文件
sudo sysdig -pc -c topfiles_bytes container.name=wordpress1
查看在wordpress1 容器里网络连接的排名情况
sudo sysdig -pc -c topconns container.name=wordpress1
显示wordpress1容器里所有命令执行的情况
sudo sysdig -pc -c spy_users container.name=wordpress1
功能是不是很强大,不过记起来有点麻烦,可以在使用的时候使用sysdig -l 查看所支持的事件列表,使用sysdig -L 查看事件所支持的过滤列表。具体也可以参看官方guide文档。
三、csysdig交互式处理
-
存档
- 2024年2月(1)
- 2024年1月(15)
- 2023年12月(2)
- 2023年11月(7)
- 2023年10月(5)
- 2023年8月(1)
- 2023年6月(3)
- 2023年5月(1)
- 2023年4月(4)
- 2023年3月(14)
- 2023年2月(8)
- 2023年1月(10)
- 2022年12月(21)
- 2022年11月(24)
- 2022年10月(16)
- 2022年9月(16)
- 2022年8月(31)
- 2022年7月(25)
- 2022年6月(10)
- 2022年5月(20)
- 2022年4月(32)
- 2022年3月(16)
- 2022年2月(9)
- 2022年1月(13)
- 2021年12月(7)
- 2021年11月(16)
- 2021年10月(8)
- 2021年9月(12)
- 2021年8月(12)
- 2021年7月(21)
- 2021年6月(13)
- 2021年5月(20)
- 2021年4月(19)
- 2021年3月(9)
- 2021年2月(3)
- 2021年1月(10)
- 2020年12月(16)
- 2020年11月(13)
- 2020年10月(2)
- 2020年9月(17)
- 2020年8月(4)
- 2020年7月(15)
- 2020年6月(5)
- 2020年5月(1)
- 2020年4月(21)
- 2020年3月(44)
- 2020年2月(20)
- 2020年1月(12)
- 2019年12月(9)
- 2019年11月(13)
- 2019年10月(44)
- 2019年9月(18)
- 2019年8月(15)
- 2019年7月(6)
- 2019年6月(17)
- 2019年5月(10)
- 2019年4月(24)
- 2019年3月(6)
- 2019年2月(2)
- 2019年1月(9)
- 2018年12月(16)
- 2018年11月(6)
- 2018年10月(10)
- 2018年9月(7)
- 2018年8月(8)
- 2018年7月(13)
- 2018年6月(20)
- 2018年5月(22)
- 2018年4月(25)
- 2018年3月(34)
- 2018年2月(9)
- 2018年1月(29)
- 2017年12月(13)
- 2017年11月(29)
- 2017年10月(19)
- 2017年9月(24)
- 2017年8月(27)
- 2017年7月(21)
- 2017年6月(35)
- 2017年5月(61)
- 2017年4月(17)
- 2017年3月(5)
- 2016年8月(1)
- 2014年3月(12)
- 2014年2月(25)
- 2014年1月(22)
- 2013年12月(29)
- 2013年11月(19)
- 2013年10月(18)
- 2013年9月(23)
- 2013年8月(24)
- 2013年7月(22)
- 2013年6月(15)
- 2013年5月(11)
- 2013年4月(36)
- 2013年3月(28)
- 2013年2月(35)
- 2013年1月(627)
-
最新文章
- docker 容器镜像日志满了,解决方案
- sshd_config 中文手册:关于ssh 设置的相关总结(ssh最大连接数、ssh连接时长、安全性配置等)
- 如何在 Linux 中使用 SSH ProxyJump 和 SSH ProxyCommand
- ubuntu - apt-get更新非交互式
- /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found
- Golang中,Aes加解密
- Go实现MD5加密的三种方法小结
- go语言 跟 php nodejs通用的加解密代码
- Win10/11 更改 WSL Docker Desktop 存储路径
- go语言使用vscodedebug 输入数据怎么调试
- ubuntu18.04安装Go语言
- 一键生成ssl证书脚本
- 一键生成自签名SSL秘钥证书
- nginx根据不同的域名将反向代理的tcp连接分流到不同的后端服务器上
- WSL2支持systemctl命令
- WSL 双系统端口映射,网络穿透最新教程
- 使用apt-mirror搭建debian本地仓库 apt源 debian源
- vscode设置打开多个标签页
- 使用IPTABLES实现对特定IP,端口流量的精确统计
- 开源免费的知识库文档管理系统(合集+排名)
- Windows 10(21H2)+ LTSC 2021 最新版MSDN官方简体中文原版ISO镜像下载地址
- Typora语法学习-自我总结笔记
- win7原版下载地址
- 解决在 Win7 旗舰版虚拟机中安装 VMware Tools 失败问题
- windows安装QT
- 使用pkg打包zx编写的nodejs程序
- nodejs库-inquirer.js
- 在nodejs代码中使用 import 替代require
- konva教程
- konva中文文档
-
热门文章