ubuntu18.04安装bcc-tools

2821 words, 9 mins

BPF Compiler Collection (BCC)是基于eBPF(extended Berkeley Packet Filters)的Linux内核分析、跟踪、网络监控工具。其源码存放于https://github.com/iovisor/bcc。

linux 性能优化里面需要大量使用 bcc-tools 工具

echo "deb [trusted=yes] https://repo.iovisor.org/apt/xenial xenial-nightly main" | sudo tee /etc/apt/sources.list.d/iovisor.list
sudo apt-get update
sudo apt-get install -y bcc-tools libbcc-examples python-bcc

常用工具

tcpconnect

tcpconnect检查活跃的TCP连接,并输出源和目的地址:

$ sudo /usr/share/bcc/tools/tcpconnect
PID    COMM         IP SADDR            DADDR            DPORT
17654  vnet-tcpNeSM 4  172.1.9.33       2.2.1.114   60792
4174   vds-cli      4  127.0.0.1        127.0.0.1        6532

filetop

filetop 查看文件读写 top 排行,而且可以看到线程 ID

$ sudo /usr/share/bcc/tools/filetop -C
Tracing... Output every 1 secs. Hit Ctrl-C to end

21:00:26 loadavg: 0.07 0.10 0.09 2/336 4227

TID    COMM             READS  WRITES R_Kb    W_Kb    T FILE
3551   ftdc             2      0      32      0       R stat
3551   ftdc             2      0      32      0       R meminfo
3551   ftdc             2      0      32      0       R diskstats
9769   AliYunDun        4      0      31      0       R stat
4408   AliSecGuard      2      0      15      0       R uptime
4408   AliSecGuard      2      0      15      0       R stat
12668  AliYunDunUpdate  2      0      15      0       R status
4227   filetop          1      0      4       0       R id
4227   filetop          2      0      2       0       R loadavg
3551   ftdc             2      0      2       0       R stat
9763   AliYunDun        1      0      0       0       R auth.log

21:00:27 loadavg: 0.07 0.10 0.09 1/333 4227

TID    COMM             READS  WRITES R_Kb    W_Kb    T FILE
3551   ftdc             2      0      32      0       R diskstats
3551   ftdc             2      0      32      0       R meminfo
3551   ftdc             2      0      32      0       R stat
9769   AliYunDun        4      0      31      0       R stat
4227   filetop          2      0      2       0       R loadavg
3551   ftdc             2      0      2       0       R stat
9763   AliYunDun        2      0      1       0       R auth.log

opensnoop

opensnoop可以看到什么文件被操作

$ sudo /usr/share/bcc/tools/opensnoop
PID    COMM               FD ERR PATH
9763   AliYunDun          27   0 /var/log/auth.log
5194   opensnoop          -1   2 /usr/lib/python2.7/encodings/ascii.x86_64-linux-gnu.so
5194   opensnoop          -1   2 /usr/lib/python2.7/encodings/ascii.so
5194   opensnoop          -1   2 /usr/lib/python2.7/encodings/asciimodule.so
5194   opensnoop          14   0 /usr/lib/python2.7/encodings/ascii.py
5194   opensnoop          15   0 /usr/lib/python2.7/encodings/ascii.pyc
541    irqbalance          6   0 /proc/interrupts
541    irqbalance          6   0 /proc/stat
541    irqbalance          6   0 /proc/irq/25/smp_affinity
541    irqbalance          6   0 /proc/irq/24/smp_affinity
541    irqbalance          6   0 /proc/irq/29/smp_affinity
541    irqbalance          6   0 /proc/irq/0/smp_affinity
541    irqbalance          6   0 /proc/irq/1/smp_affinity
541    irqbalance          6   0 /proc/irq/4/smp_affinity
541    irqbalance          6   0 /proc/irq/6/smp_affinity
541    irqbalance          6   0 /proc/irq/8/smp_affinity
541    irqbalance          6   0 /proc/irq/12/smp_affinity
541    irqbalance          6   0 /proc/irq/14/smp_affinity
541    irqbalance          6   0 /proc/irq/15/smp_affinity
9763   AliYunDun          27   0 /proc/9763/stat
9763   AliYunDun          27   0 /sys/devices/system/cpu
9763   AliYunDun          27   0 /proc/9763/stat
3468   mongod             35   0 /var/lib/mongodb/journal
3468   mongod             35   0 /var/lib/mongodb/journal
3468   ftdc               35   0 /proc/3468/stat
3468   ftdc               35   0 /proc/3468/stat
3468   ftdc               35   0 /proc/stat
3468   ftdc               35   0 /proc/meminfo
3468   ftdc               35   0 /proc/diskstats
9763   AliYunDun          27   0 /var/log/auth.log
17654  bitcoin-msghand   356   0 /home/ubuntu/.vds/bitcoin/chainstate/2646610.ldb
9763   AliYunDun          27   0 /proc/9763/stat
9763   AliYunDun          27   0 /sys/devices/system/cpu
9763   AliYunDun          27   0 /proc/9763/stat
3468   mongod             35   0 /var/lib/mongodb/journal
3468   mongod             35   0 /var/lib/mongodb/journal
9763   AliYunDun          27   0 /var/log/auth.log
17654  bitcoin-msghand   355   0 /home/ubuntu/.vds/bitcoin/chainstate/2646428.ldb
17654  bitcoin-msghand   355   0 /home/ubuntu/.vds/bitcoin/chainstate/2646338.ldb