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

简介:

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

1.网络

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

 
 
  1. sysdig -c topprocs_net 

显示主机192.168.0.1的网络传输数据:

 
 
  1. as binary 
  2. sysdig -s2000 -X -c echo_fds fd.cip=192.168.0.1  
  3. as ASCII:  
  4. sysdig -s2000 -A -c echo_fds fd.cip=192.168.0.1 

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

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

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

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

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

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

2.容器

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

 
 
  1. sudo csysdig -vcontainers 

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

 
 
  1. sudo csysdig -pc 

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

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

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

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

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

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

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

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

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

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

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

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

3.应用

查看机器所有的HTTP请求:

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

查看机器所有的SQL select查询:

 
 
  1. sudo sysdig -s 2000 -A -c echo_fds evt.buffer contains SELECT  
  2. See queries made via apache to an external MySQL server happening in real time  
  3. sysdig -s 2000 -A -c echo_fds fd.sip=192.168.30.5 and proc.name=apache2 and evt.buffer contains SELECT 

4.硬盘 I/O

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

 
 
  1. sysdig -c topprocs_file 

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

 
 
  1. sysdig -c fdcount_by proc.name "fd.type=file"  
  2. See the top files in terms of read+write bytes  
  3. sysdig -c topfiles_bytes  
  4. Print the top files that apache has been reading from or writing to  
  5. sysdig -c topfiles_bytes proc.name=httpd  
  6. Basic opensnoop: snoop file opens as they occur  
  7. sysdig -p "%12user.name %6proc.pid %12proc.name %3fd.num %fd.typechar %fd.name" evt.type=open  
  8. See the top directories in terms of R+W disk activity  
  9. sysdig -c fdbytes_by fd.directory "fd.type=file"  
  10. See the top files in terms of R+W disk activity in the /tmp directory  
  11. sysdig -c fdbytes_by fd.filename "fd.directory=/tmp/"  
  12. Observe the I/O activity on all the files named 'passwd'  
  13. sysdig -A -c echo_fds "fd.filename=passwd"  
  14. Display I/O activity by FD type  
  15. sysdig -c fdbytes_by fd.type 

进程和CPU使用率:

 
 
  1. See the top processes in terms of CPU usage  
  2. sysdig -c topprocs_cpu  
  3. See the top processes for CPU 0  
  4. sysdig -c topprocs_cpu evt.cpu=0  
  5. Observe the standard output of a process  
  6. sysdig -s4096 -A -c stdout proc.name=cat 

性能和错误:

 
 
  1. See the files where most time has been spent  
  2. sysdig -c topfiles_time  
  3. See the files where apache spent most time  
  4. sysdig -c topfiles_time proc.name=httpd  
  5. See the top processes in terms of I/O errors  
  6. sysdig -c topprocs_errors  
  7. See the top files in terms of I/O errors  
  8. sysdig -c topfiles_errors  
  9. See all the failed disk I/O calls  
  10. sysdig fd.type=file and evt.failed=true  
  11. See all the failed file opens by httpd  
  12. sysdig "proc.name=httpd and evt.type=open and evt.failed=true"  
  13. See the system calls where most time has been spent  
  14. sysdig -c topscalls_time  
  15. See the top system calls returning errors  
  16. sysdig -c topscalls "evt.failed=true"  
  17. snoop failed file opens as they occur  
  18. sysdig -p "%12user.name %6proc.pid %12proc.name %3fd.num %fd.typechar %fd.name" evt.type=open and evt.failed=true  
  19. Print the file I/O calls that have a latency greater than 1ms:  
  20. sysdig -c fileslower 1 

5.安全

 
 
  1. Show the directories that the user "root" visits  
  2. sysdig -p"%evt.arg.path" "evt.type=chdir and user.name=root"  
  3. Observe ssh activity  
  4. sysdig -A -c echo_fds fd.name=/dev/ptmx and proc.name=sshd  
  5. Show every file open that happens in /etc  
  6. sysdig evt.type=open and fd.name contains /etc  
  7. Show the ID of all the login shells that have launched the "tar" command  
  8. sysdig -r file.scap -c list_login_shells tar  
  9. Show all the commands executed by the login shell with the given ID  
  10. sysdig -r trace.scap.gz -c spy_users proc.loginshellid=5459 




本文作者:佚名
来源:51CTO

目录
相关文章
|
1月前
|
监控 Linux Shell
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
39 0
|
2天前
|
Linux 应用服务中间件 PHP
性能工具之linux常见日志统计分析命令
通过本文的介绍,我相信同学们一定会发现 linux三剑客强大之处。在命令行中,它还能够接受,和执行外部的 AWK 程序文件,可以对文本信息进行非常复杂的处理,可以说“只有想不到的,没有它做不到的。
33 1
|
30天前
|
运维 监控 算法
【C/C++ 实用工具】网络监控工具一览
【C/C++ 实用工具】网络监控工具一览
24 0
|
1月前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】⭐⭐⭐Linux 实时监控系统性能 top命令 使用指南
【Shell 命令集合 系统管理 】⭐⭐⭐Linux 实时监控系统性能 top命令 使用指南
40 2
|
2月前
|
应用服务中间件 API nginx
|
6月前
|
监控 Shell 持续交付
编写Shell脚本以自动化单位网络监控软件的部署和配置
在今天的数字化世界中,网络监控软件已经成为确保网络稳定性和安全性的不可或缺的工具。然而,手动部署和配置这些软件可以是一项繁琐的任务。本文将介绍如何使用Shell脚本自动化这一过程,以便轻松监控网络,并讨论如何将监控数据自动提交到网站。
205 0
|
监控 Linux 测试技术
性能测试 基于Python结合InfluxDB及Grafana图表实时采集Linux多主机或Docker容器性能数据
性能测试 基于Python结合InfluxDB及Grafana图表实时采集Linux多主机或Docker容器性能数据
173 0
|
监控 Linux
服务监控系统WGCLOUD - 一键部署agent脚本说明(Linux版)
这个目前是只适用于Linux版本的agent一键部署,会默认自动下载指定的agent安装包,并自动部署启动
|
监控 网络协议 Unix
快速学习Linux常用性能监控命令及工具
在linux系统环境的测试开发过程中,我们常常需要评估系统性能,尤其在性能测试工作中,我们需要通过系统资源的监控,从而分析定位系统的性能瓶颈。
147 0
快速学习Linux常用性能监控命令及工具
|
前端开发 网络协议 Linux
问题排查利器:Linux 原生跟踪工具 Ftrace 必知必会
问题排查利器:Linux 原生跟踪工具 Ftrace 必知必会
437 0