美文网首页Docker的那些事儿
Docker的那些事儿—Docker监控工具:Sysdig

Docker的那些事儿—Docker监控工具:Sysdig

作者: sjyu_eadd | 来源:发表于2018-03-31 23:48 被阅读11次

    Sysdig = system(系统)+dig(挖掘)。Sysdig 是一个开源系统发掘工具,用于系统级别的勘察和排障,可以把它看作一系列Linux系统工具的组合,主要包括:

    strace:追踪某个进程产生和接收的系统调用。

    tcpdump:分析网络数据,监控原始网络通信。

    lsof: list opened files, 列出打开的文件。

    top:监控系统性能工具。

    htop :交互式的进程浏览器,可以用来替换 top 命令。

    iftop :主要用来显示本机网络流量情况及各相互通信的流量集合。

    lua:一个小巧的脚本语言。该语言的设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能。

    Sysdig 的特性之一在于它不仅能分析Linux 系统的“现场”状态,也能将该状态保存为转储文件以供离线分析检查。你也可以自定义 Sysdig 的行为,通过内建的名为凿子(chisel)的小脚本增强其功能。所以 Sysdig 经常被翻译为系统之锹。通过 Sysdig 工具,用户能够很方便地查看到主机上所有应用程序的cpu、文件 i/o、网络访问状况,这个工具最初的产生就是为了取代传统服务器上的一系列系统检测工具如strace、tcpdump、htop、iftop、lsof 等。它的logo被设计为一个铲子的轮廓,这就寓意着Sysdig对系统信息的强大挖掘能力。

    Sysdig不仅可以快速进行系统数据的收集和分析,而且还专门提供了容器级别的信息采集命令,支持查看指定容器之间的网络流量、查看特定容器的 CPU使用情况等。下图是 Sysdig 监控 Docker 容器的示意图。

    下面先来看下Sysdig的安装:

    Sysdig官方提供三种安装方式(以Ubuntu系统为例):

    1、一键安装

    以root用户执行:

    curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash

    然后install-sysdig脚本会下载对应的系统版本进行自动安装。

    2、手动安装

    curl -s https://s3.amazonaws.com/download.draios.com/DRAIOS-GPG-KEY.public | apt-keyadd -

    curl -s -o /etc/apt/sources.list.d/draios.listhttp://download.draios.com/stable/deb/draios.list

    apt-get update

    apt-get -y install linux-headers-$(uname -r)

    apt-get- y install sysdig

    3、容器方式,Sysdig提供了docker镜像包,我们可以以容器方式运行Sysdig

    docker run -i -t \

    --name sysdig \

    --privileged\

    -v /var/run/docker.sock:/host/var/run/docker.sock \

    -v /dev:/host/dev \

    -v /proc:/host/proc:ro \

    -v /boot:/host/boot:ro \

    -v /lib/modules:/host/lib/modules:ro \

    -v /usr:/host/usr:ro \

    sysdig/sysdig

    Sysdig安装后,我们就可以体验Sysdig的强大功能了。

    首先,Sysdig提供了强大的交互式工具——csysdig(这个top命令类似)

    终端输入csysdig,默认进入系统Processes监控页面(上图)

    最上面显示目前监控的是整个系统Processes

    中间动态实时显示系统Processes的变化

    最下面是快捷键说明

    按F2进入Views页面

    中间左面,列出了sysdig监控的项目,如Processes、Directories、Containers、K8s Controllers等等,右面展示监控的详细信息说明

    按上下方向键选择Containers

    按Enter进入Containers监控页面

    可以看到目前host上启动的所有containers的情况

    上下方向键选择具体某个container,按enter键,可以看到weavescope容器内Processes(默认,可以通过F2选择查看Files、Threads等等)

    当然sysdig也提供了非交互式的命令——sysdig

    比如查询容器weavescope 的cpu变化:

    sysdig -pc -c topprocs_cpu container.name=weavescope

    下面是sysdig --help给出的examples,sysdig的命令还是相对比较全面的。有兴趣的读者可以体验下。a

    Capture all the events from the live system and print them to screen

       $sysdig

    Capture all the events from the live system and save them to disk

       $sysdig -w dumpfile.scap

    Read events from a file and print them to screen

       $sysdig -r dumpfile.scap

    Print all the open system calls invoked by cat

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

    Print the name of the files opened by cat

       $sysdig -p"%evt.arg.name" proc.name=cat and evt.type=open

    相关文章

      网友评论

        本文标题:Docker的那些事儿—Docker监控工具:Sysdig

        本文链接:https://www.haomeiwen.com/subject/oyancftx.html