分析容器系统调用:Sysdig

Sysdig is an open-source, cross-platform, powerful and flexible system monitoring and troubleshooting tool for Linux; it also works on Windows and Mac OSX but with limited functionality and can be used for system analysis, inspection and debugging.

Normally, you would employ a mix of various Linux performance monitoring and troubleshooting tools including these ones listed below to perform the Linux monitoring and debugging tasks:

  1. strace – discover system calls and signals to a process.
  2. tcpdump – raw network traffic monitoring.
  3. netstat – network connections monitoring.
  4. htop – real time process monitoring.
  5. iftop – real time network bandwidth monitoring.
  6. lsof – view which files are opened by which process.

However, sysdig integrates what all the above tools and many more, offer in a single and simple program, more so with amazing container support. It enables you to capture, save, filter and examine the real behavior (stream of events) of Linux systems as well as containers.

It comes with a command line interface and a powerful interactive UI (csysdig) which allow you to watch system activity in real time, or perform a trace dump and save for later analysis. 

Sysdig Features:

  • It is fast, stable and easy-to-use with comprehensively well documented.
  • Comes with native support for container technologies, including Docker, LXC.
  • It is scriptable in Lua; offers chisels (lightweight Lua scripts) for processing captured system events.
  • Supports useful filtering of output.
  • Supports system and application tracing.
  • It can be integrated with Ansible, Puppet and Logstash.
  • Enable sample advanced log analysis.
  • It also offers Linux server attack (forensics) analysis features for ethical hackers and lot’s more.

 

分析容器系统调用:Sysdig


Sysdig:一个非常强大的系统监控、分析和故障排查工具。 汇聚 strace+tcpdump+htop+iftop+lsof 工具功能于一身!(核心的功能就是将工具整合在一块)
sysdig 除了能获取系统资源利用率、进程、网络连接、系统调用等信息, 还具备了很强的分析能力,例如:
• 按照CPU使用率对进程排序
• 按照数据包对进程排序
• 打开最多的文件描述符进程
• 查看进程打开了哪些文件
• 查看进程的HTTP请求报文
• 查看机器上容器列表及资源使用情况
sysdig 通过在内核的驱动模块注册系统调用的 hook,这样当有系统调用发生和完成的时候,它会把系统调用信息拷贝到特定的buffer,然后用户态组件对数据信息处理(解压、解析、过滤等),
并最终通过 sysdig 命令行和用户进行交互。

 

 哪台机器有问题就可以去安装,使用这个工具

rpm --import https://s3.amazonaws.com/download.draios.com/DRAIOS-GPG-KEY.public 
curl -s -o /etc/yum.repos.d/draios.repo https://s3.amazonaws.com/download.draios.com/stable/rpm/draios.repo
yum install epel-release -y
yum install sysdig -y /usr/bin/sysdig-probe-loader # 加载驱动模块


[root@master ~]# lsmod | grep ip_vs
ip_vs_sh               12688  0 
ip_vs_wrr              12697  0 
ip_vs_rr               12600  37 
ip_vs                 145458  43 ip_vs_rr,ip_vs_sh,ip_vs_wrr
nf_conntrack          139264  10 ip_vs,xt_CT,nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_netlink,nf_conntrack_ipv4,nf_conntrack_ipv6
libcrc32c              12644  3 ip_vs,nf_nat,nf_conntrack
[root@master ~]# lsmod | grep netfilter
br_netfilter           22256  0 
bridge                151336  1 br_netfilter
[root@master ~]# lsmod | grep sysdig
sysdig_probe          639433  0 
sysdig常用参数:
• -l, --list:列出可用于过滤和输出的字段
• -M <num_seconds> :多少秒后停止收集
• -p <output_format>, --print=<output_format> :指定打印事件时使用的格式
• 使用-pc或-pcontainer 容器友好的格式
• 使用-pk或-pkubernetes k8s友好的格式
• -c <chiselname> <chiselargs>:指定内置工具,可直接完成具体的数据聚合、分析工作
• -w <filename>:保存到文件中
• -r <filename>:从文件中读取

执行sysdig命令,实时输出大量系统调用。
示例:59509 23:59:19.023099531 0 kubelet (1738) < epoll_ctl
格式:%evt.num %evt.outputtime %evt.cpu %proc.name (%thread.tid) %evt.dir %evt.type %evt.info
• evt.num: 递增的事件号
• evt.time: 事件发生的时间
• evt.cpu: 事件被捕获时所在的 CPU,也就是系统调用是在哪个 CPU 执行的
• proc.name: 生成事件的进程名字
• thread.tid: 线程的 id,如果是单线程的程序,这也是进程的 pid
• evt.dir: 事件的方向(direction),> 代表进入事件,< 代表退出事件
• evt.type: 事件的名称,比如 open、stat等,一般是系统调用
• evt.args: 事件的参数。如果是系统调用,这些对应着系统调用的参数
自定义格式输出:sysdig -p "user:%user.name time:%evt.time proc_name:%proc.name"
[root@master ~]# sysdig -p "user:%user.name time:%evt.time proc_name:%proc.name" -M 3 -w xxx
[root@master ~]# sysdig -r  xxx

sysdig过滤:

• fd:根据文件描述符过滤,比如 fd 标号(fd.num)、fd 名字(fd.name)
• process:根据进程信息过滤,比如进程 id(proc.id)、进程名(proc.name)
• evt:根据事件信息过滤,比如事件编号、事件名
• user:根据用户信息过滤,比如用户 id、用户名、用户 home 目录
• syslog:根据系统日志过滤,比如日志的严重程度、日志的内容
• container:根据容器信息过滤,比如容器ID、容器名称、容器镜像
查看完整过滤器列表:sysdig -l

示例:
1、查看一个进程的系统调用
sysdig proc.name=kubelet
2、查看建立TCP连接的事件
sysdig evt.type=accept
3、查看/etc目录下打开的文件描述符
sysdig fd.name contains /etc
4、查看容器的系统调用
sysdig -M 10 container.name=web
注:还支持运算操作符,=、!=、>=、>、<、
<=、contains、in 、exists、and、or、not

Chisels: 实用的工具箱,一组预定义的功能集合,用来分析特定的场景。
sysdig –cl 列出所有Chisels,以下是一些常用的:
• topprocs_cpu:输出按照 CPU 使用率排序的进程列表,例如sysdig -c
• topprocs_net:输出进程使用网络TOP
• topprocs_file:进程读写磁盘文件TOP
• topfiles_bytes:读写磁盘文件TOP
• netstat:列出网络的连接情况

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS是一种流行的Linux操作系统,它支持添加自定义系统调用。添加自定义系统调用可以增强操作系统的功能,并能为用户提供更多便利的功能。编写一个使用新增系统调用或新增设备驱动功能的应用程序可以实现多种实用功能。 首先,我们需要定义新的系统调用。在创建新的系统调用之前,需要了解Linux内核的框架和系统调用的实现方式。在CentOS中,我们可以使用systemtap等工具来调试和跟踪系统调用。一旦新的系统调用被创建,编写支持此新系统调用的应用程序就变得可行。 假设我们的新系统调用是用于查询硬盘健康状态的,我们可以编写一个应用程序来使用此系统调用。我们可以使用C语言编写适当的代码,以获得所需信息并将其显示在屏幕上。首先需要在代码中声明新的系统调用,以允许应用程序使用该调用。然后我们可以通过调用系统调用获取所需的硬盘状态信息,并将其显示给用户。 另一个例子是使用新增设备驱动功能。通过创建新的设备驱动程序,我们可以将设备与操作系统进行集成,实现正常的操作和数据传输。然后我们可以编写相应的应用程序,以利用新的设备驱动程序,获取并处理设备数据。例如,我们可以使用额外的设备驱动程序和应用程序来控制风扇的转速和温度传感器的读取,以便更好地控制电脑的温度。 总之,CentOS添加系统调用和设备驱动功能可以为用户提供更多自定义功能。我们只需要编写相应的应用程序,以利用这些新增的特性,便能为用户带来更好的使用体验和更高的灵活性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值