功能强大的系统工具Sysdig命令实例介绍

运维 系统运维 Linux
Sysdig是一个能够让系统管理员和开发人员以前所未有方式洞察其系统行为的监控工具。我们可以用sysdig命令做很多很酷的事情。你如果有更有趣的用法,想添加到下面的命令例子中,请告诉我们!

  Sysdig是一个能够让系统管理员和开发人员以***方式洞察其系统行为的监控工具。我们可以用sysdig命令做很多很酷的事情。你如果有更有趣的用法,想添加到下面的命令例子中,请告诉我们!

[[154652]]

  1.网络

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

sysdig -c topprocs_net 
  • 1.

  显示主机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 
  • 1.
  • 2.
  • 3.
  • 4.

  查看连接最多的服务器端口:

 

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 
  • 1.
  • 2.
  • 3.
  • 4.

  查看客户端连接最多的ip:

 

in terms of established connections  
sysdig -c fdcount_by fd.cip "evt.type=accept"  
in terms of total bytes  
sysdig -c fdbytes_by fd.cip 
  • 1.
  • 2.
  • 3.
  • 4.

  列出所有不是访问apache服务的访问连接:  

sysdig -p"%proc.name %fd.name" "evt.type=accept and proc.name!=httpd" 
  • 1.

  2.容器

  查看机器上运行的容器列表及其资源使用情况:  

sudo csysdig -vcontainers 
  • 1.

  查看容器上下文的进程列表:  

sudo csysdig -pc 
  • 1.

  查看运行在wordpress1容器里CPU的使用率:  

sudo sysdig -pc -c topprocs_cpu container.name=wordpress1 
  • 1.

  查看运行在wordpress1容器里网络带宽的使用率:  

sudo sysdig -pc -c topprocs_net container.name=wordpress1 
  • 1.

  查看在wordpress1容器里使用网络带宽最多的进程:  

sudo sysdig -pc -c topprocs_net container.name=wordpress1 
  • 1.

  查看在wordpress1 容器里占用 I/O 字节最多的文件:  

sudo sysdig -pc -c topfiles_bytes container.name=wordpress1 
  • 1.

  查看在wordpress1 容器里网络连接的排名情况:  

sudo sysdig -pc -c topconns container.name=wordpress1 
  • 1.

  显示wordpress1容器里所有命令执行的情况:  

sudo sysdig -pc -c spy_users container.name=wordpress1 
  • 1.

  3.应用

  查看机器所有的HTTP请求:  

sudo sysdig -s 2000 -A -c echo_fds fd.port=80 and evt.buffer contains GET 
  • 1.

  查看机器所有的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 
  • 1.
  • 2.
  • 3.

  4.硬盘 I/O

  查看使用硬盘带宽最多的进程:  

sysdig -c topprocs_file 
  • 1.

  列出使用大量文件描述符的进程:

 

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 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

  进程和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 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

  性能和错误:

 

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 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.

  5.安全

 

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/ptmx 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 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

  原文:http://www.sysdig.org/wiki/sysdig-examples/

责任编辑:火凤凰 来源: 运维帮
相关推荐

2010-03-05 09:19:54

Android系统

2021-07-09 10:14:05

IP工具命令

2017-04-20 18:00:59

Linux命令行工具系统信息

2011-04-15 09:27:09

Windows PhoWindows phoMango

2023-12-19 09:00:03

OCR软件开源Ocrad

2020-06-19 09:35:58

备份Linux系统工具

2013-01-23 11:30:39

JSVirtualKeybjQuery

2020-12-15 15:08:17

工具Java线程

2020-12-15 07:54:40

工具Hutoolgithub

2020-12-24 17:08:52

安全工具NoSql注入接口工具

2021-10-10 12:17:06

Weakpass在线字典生成器安全工具

2024-01-15 18:02:09

docker系统文件格式

2021-11-01 05:53:08

Doldrums逆向工程分析工具安全工具

2022-08-18 11:36:28

网络嗅探工具网络安全

2010-03-04 13:36:55

openSUSE

2010-02-24 17:58:28

Python 测试框架

2022-10-10 10:14:38

Python绘图库

2009-07-07 08:46:11

微软Windows 7新功能

2010-02-03 17:01:14

2024-06-18 07:50:43

点赞
收藏

51CTO技术栈公众号