• 安装方法:
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash

[root@localhost ~]# curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash
* Detecting operating system
* Installing EPEL repository (for DKMS)
* Installing Draios public key
* Installing Draios repository
* Installing kernel headers
省略。。。。

安装完成后二话不说直接执行 sysdig,注意出现刷屏后随时按ctrl-c

1187 11:24: data=root:x:0:.bin:x:1:.daemon:x:2:.sys:x:3:.adm:x:4:.tty:x:5:.disk:x:6:.lp:x:7:.mem:
1264 11:24:27.109080267 0 systemd-udevd (489) > close fd=14(<f>/etc/group)
1265 11:24:27.109080581 0 systemd-udevd (489) < close res=0
1266 11:24:27.109082572 0 systemd-udevd (489) > munmap addr=7F4CE05B7000 length=4096
1267 11:24:27.109085958 0 systemd-udevd (489) < munmap res=0 vm_size=45468 vm_rss=1984 vm_swap=1228
1268 11:24:27.109089928 0 systemd-udevd (489) > read fd=13(<f>/usr/lib/udev/rules.d/69-cd-sensors.rules) size=4096
1269 11:24:27.109090545 0 systemd-udevd (489) < read res=0 data=
1270 11:24:27.109090992 0 systemd-udevd (489) > close fd=13(<f>/usr/lib/udev/rules.d/69-cd-sensors.rules)
1271 11:24:27.109091119 0 systemd-udevd (489) < close res=0
1272 11:24:27.109091753 0 systemd-udevd (489) > munmap addr=7F4CE05B8000 length=4096
1273 11:24:27.109093095 0 systemd-udevd (489) < munmap res=0 vm_size=45464 vm_rss=1980 vm_swap=1228
1274 11:24:27.109094748 0 systemd-udevd (489) > stat

有点类似strace、tcpdump的输出。其输出的信息含义为:

%evt.num %evt.time %evt.cpu %proc.name (%thread.tid) %evt.dir %evt.type %evt.args

当中:

	* evt.num 是自增的事件号
* evt.time 是事件发生的时间戳
* evt.cpu 是捕获事件所在的CPU号
* proc.name 是产生事件的进程名称
* thread.tid is 产生事件的线程id
* evt.dir 是事件方向, > 表示进入事件 < 表示退出事件
* evt.type 是事件名称, 如 'open' or 'read'
* evt.args 事件的參数列表
  • 文件输入输出:

使用-w选项把输出信息保存为文件:

$ sysdig –w myfile.scap

-n选项指定行数:

$ sysdig –n 100 –w myfile.scap

-r选项表示从已保存的文件读出并输出:

$ sysdig –r myfile.scap

  • 过滤器:

sysdig的过滤器有点像tcpdump。前面有说到输出格式的详细含义。这里的过滤器就能够对随意的一项进行设定,比方我对sshd进程进行过滤:

[root@localhost ~]# sysdig proc.name=sshd
29255 11:44:47.958210052 0 sshd (2131) > clock_gettime
29256 11:44:47.958210248 0 sshd (2131) < clock_gettime
29257 11:44:47.958211128 0 sshd (2131) > select
29258 11:44:47.958212200 0 sshd (2131) < select res=1
29259 11:44:47.958212428 0 sshd (2131) > rt_sigprocmask
29260 11:44:47.958212625 0 sshd (2131) < rt_sigprocmask
29261 11:44:47.958213022 0 sshd (2131) > rt_sigprocmask
29262 11:44:47.958213187 0 sshd (2131) < rt_sigprocmask
29263 11:44:47.958213389 0 sshd (2131) > clock_gettime
29264 11:44:47.958213535 0 sshd (2131) < clock_gettime
29265 11:44:47.958214129 0 sshd (2131) > write fd=3(<4t>192.168.1.12:4686->10.18.5.47:22) size=2660
29266 11:44:47.958283315 0 sshd (2131) < write res=2660 data=.r.t..T.=..........{........<).......3.....Y>G..4.M.s..]....Q.1hAN...s.z.....B..
29267 11:44:47.958284557 0 sshd (2131) > clock_gettime
29268 11:44:47.958284822 0 sshd (2131) < clock_gettime
29269 11:44:47.958285308 0 sshd (2131) > select
29270 11:44:47.958287711 0 sshd (2131) > switch next=0 pgft_maj=8 pgft_min=1714 vm_size=135212 vm_rss=2320 vm_swap=0
29272 11:44:47.958519093 0 sshd (2131) < select res=1
29273 11:44:47.958520932 0 sshd (2131) > rt_sigprocmask
29274 11:44:47.958521450 0 sshd (2131) < rt_sigprocmask
29275 11:44:47.958521687 0 sshd (2131) > rt_sigprocmask
29276 11:44:47.958521860 0 sshd (2131) < rt_sigprocmask

这是很经常使用的过滤方式,一般我们都是对特定进程感兴趣。指定进程名称后就可以捕获到全部的系统调用事件。

类似tcpdump,sysdig也支持下面比較符号和布尔符号:

standard comparison operators(=, !=, <, <=, >, >=, contains)

Boolean operators (and, or and not)

$ sysdig proc.name=cat or proc.name=vi

捕获cat或者vi进程的系统调用,这里用到or

$ sysdig proc.name!=cat and evt.type=open

显示除了cat进程以外的open调用

$ sysdig -l
----------------------
Field Class: fd fd.num the unique number identifying the file descriptor.
fd.type type of FD. Can be 'file', 'directory', 'ipv4', 'ipv6', 'unix',
'pipe', 'event', 'signalfd', 'eventpoll', 'inotify' or 'signal
fd'.
fd.typechar type of FD as a single character. Can be 'f' for file, 4 for IP
v4 socket, 6 for IPv6 socket, 'u' for unix socket, p for pipe,
'e' for eventfd, 's' for signalfd, 'l' for eventpoll, 'i' for i
notify, 'o' for uknown.
fd.name FD full name. If the fd is a file, this field contains the full
path. If the FD is a socket, this field contain the connection
tuple.
fd.directory If the fd is a file, the directory that contains it.
fd.filename If the fd is a file, the filename without the path.
fd.ip matches the ip address (client or server) of the fd.
fd.cip client IP address.
fd.sip server IP address.
fd.lip local IP address.
省略。 。。 。

-l选项会列出全部能够使用的字段,我们能够用这里显示的字段自行匹配须要的信息

好好利用这些有用的字段能够依据自己详细情况做各种系统调用的监測,

比方你想捕获一下本机除了nginx以外的其它网络链接情况能够这样:

$ sysdig evt.type=accept and proc.name!=nginx

  • evt.arg 与 evt.rawarg

这两个字段须要特别解释一下,由sysdig捕获的事件通常是属于某种类型(如 open \ read)。以及一系列參数(如 fd \ name)。

sysdig强大之处在于能够使用过滤器来过滤參数

$ sysdig evt.type=execve and evt.arg.ptid=bash

这个过滤器表示对父进程名字为bash的的execve系统调用进行过滤,evt.arg and event.rawarg的差别是后者不正确PID、FD。error codes等进行解析。

$ sysdig evt.arg.res=ENOENT

这个能够用来捕获一个特定的I/O错误,这个值一般是负数

$ sysdig " evt.rawarg.res<0 or evt.rawarg.fd<0"

会给你全部产生错误的系统调用。

  • 获得全部的系统调用
$ sysdig –L
输出省略。。。
  • 查看可用的凿子列表
$ sysdig -cl | less

默认有下面类目可用,各个类目中分布有多个内建的凿子。

	* CPU Usage:CPU使用量
* Errors:错误
* I/O
* Logs:日志
* Misc:混杂
* Net:网络
* Performance:性能
* Security:安全
* System State:系统状态
  • sysdig实例:

我们可能常常会遇到监控网络I/O的情况,对于sysdig。能够非常easy进行通信嗅探,其风格更为对用户友好。

比如,你能够检查由特定IP地址,特定进程(如nginx)提供的数据(ASCII编码格式):

# sysdig -s 4096 -A -c echo_fds fd.cip=192.168.1.100 -r /tmp/sysdig-scap.gz proc.name=nginx

假设你想要监控原生传输数据(二进制格式)。请把“-A”替换为“-X”:

# sysdig -s 4096 -X -c echo_fds fd.cip=192.168.1.100 -r /tmp/sysdig-scap.gz proc.name=nginx

最新文章

  1. Web开发安全之文件上传安全
  2. DOM性能小记
  3. Android-Selector用法
  4. How Uuencoding Works
  5. 2013 Multi-University Training Contest 2 Balls Rearrangement
  6. 跟我学android-Android应用结构分析(四)
  7. 通过jdbc取得数据库表结构信息
  8. js获取选中日期的当周的周一和周日
  9. Nginx模块开发与架构解析(nginx安装、配置说明)
  10. input type = file 上传图片转为base64
  11. mysql 5.7 运维命令
  12. 防爆等级介绍 - IP65防爆等级和dIIBT4防爆等级的有什么区别?
  13. 如何屏蔽SkylineGlobe提供的三维地图控件上的快捷键
  14. 在AngularJS中实现一个延迟加载的Directive
  15. 36. Oracle查询数据库中所有表的记录数
  16. bootstrap实现左侧图片右侧文字布局
  17. 自动化测试--响应请求测试(.net)
  18. InnerHTML属性的XSS利用
  19. Thunder团队Beta周贡献分规则
  20. 【JavaScript】setinterval和setTimeout的区别

热门文章

  1. React Native常用组件在Android和IOS上的不同
  2. MFC SkinMagic使用方法
  3. html——表单控件
  4. Git与SVN版本控制系统
  5. Python学习【第7篇】:Python之常用模块2
  6. POJ 2823 Sliding Window &amp; Luogu P1886 滑动窗口
  7. input chrome下输入之后背景变为黄色的解决办法
  8. linu学习第一天:基础知识
  9. openoffice启动服务并将office文件转换为pdf文件
  10. ASP.NET误人子弟教程:在MVC下如何返回图片