1 Star 0 Fork 0

Bytedance Inc. / netatop-bpf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

netatop-bpf

Introduction

The Linux kernel does not maintain counters for the number of network accesses issued per process. As a consequence, it is not possible to analyze which process causes most load in case that atop shows a high utilization on one of your network interfaces.(For performance reasons, threads are not counted.)

The optional netatop-bpf can be loaded to gather statistics about the TCP and UDP packets that have been transmitted/received per process. As soon as atop discovers that netatop-bpf is active, it shows the columns SNET and RNET in the generic screen for the number of transmitted and received packets per process. When the 'n' key is pressed, it shows detailed counters about the number packets transmitted/received via TCP and UDP, the average sizes of these packets, and the total bandwidth consumed for input and output per process/thread.

The bpf program hooks the transport layer of the network Protocol Stack to count information in the map when sending and receiving data packets. The hook function is the tracepoint merged in kernel 6.3. When a network event occurs and it is TCP/UDP protocol, it will reach the function processing of the transport layer, and the function registered on the hook point will be triggered. The main function is to maintain statistics on the network traffic of per process in the map.

  • Kernel (>= 6.3) merged tracepoint:
    • tracepoint/sock/sock_sendmsg_length
    • tracepoint/sock/sock_recvmsg_length

Netatop runs normally and it has two functions. One is responsible for loading the bpf program to the kernel and communicating with the bpf program through the bpf map; the other is to communicate with atop through the Unix Domain Socket.

Atop send to netatop every interval(default 10s), netatop recv from atop and then traverses the bpf map sending all process information to atop, atop uses the hash table to store the information of all processes, and then traverses the /proc file (exits the process) to obtain the pid of the process and find the hashmap.

Building

netatop supports kernel version >= 6.3

Install Dependencies

You will need clang (at least v11 or later), libelf and zlib to build the examples, package names may vary across distros.

On Debian/Ubuntu, you need:

$ apt install clang libelf1 libelf-dev zlib1g-dev

Getting the source code

Download the git repository and check out submodules:

git clone --recurse-submodules git@github.com:bytedance/netatop-bpf.git

C Examples Makefile build:

$ cd netatop-bpf
$ git submodule update --init --recursive       # check out libbpf
$ make
$ make install
BSD 3-Clause License Copyright (c) 2020, Andrii Nakryiko All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
C 等 4 种语言
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/ByteDance/netatop-bpf.git
git@gitee.com:ByteDance/netatop-bpf.git
ByteDance
netatop-bpf
netatop-bpf
main

搜索帮助