Giter Site home page Giter Site logo

ebpf-tracing-demo's Introduction

Introduction

This repository hosts an eBPF program designed to monitor HTTP traffic on a server, tracking metrics such as request counts, response totals, success rates, and the latency (average, minimum, maximum) associated with requests per IP address.

The core strategy involves integrating a function within the eBPF socket filter to intercept both incoming and outgoing HTTP traffic, subsequently storing this data in a BPF map for further analysis by a userspace application.

To emulate server response times, we've developed a Python web application server. This server randomly generates an integer, pauses for "x" milliseconds (where 0 < x < 10), and then sends this number back to the client. Should this number be divisible by 5, the server issues an HTTP 500 error to mimic a request failure.

An alternative method for HTTP traffic capture involves embedding an eBPF program within system call functions, such as accept4, read, write, and close, regarding socket operations. The code for this approach will be submitted soon.

Below is the guideline to run the program.

Installing BCC

Currently, BCC packages for both the Ubuntu Universe, and the iovisor builds are outdated. This is a known and tracked in:

Run below commands in sudo

sudo add-apt-repository ppa:hadret/bpfcc
sudo apt update
sudo apt-get install bpfcc-tools linux-headers-$(uname -r)

Installing Docker Compose

Using docker.sh script

Run the program

Run docker compose file to get docker bridge name

sudo docker compose up --build

Get bridge name of client network, for example we will monitor interface br-2b4e89c112d8

Run the app server

sudo apt-get -y install python3-pip
pip install flask
python3 app.py
# if you want to run multiple services, use below command in two terminals
flask run --host=0.0.0.0 --port=8080
flask run --host=0.0.0.0 --port=8888

Run the eBPF program (with sudo)

python3 ./http_filter.py -i br-2b4e89c112d8

Open another terminal to run the docker compose again to send HTTP request and you can see the result from eBPF program

Version 2 (monitor by port for multiple services)

Reference

The program is developed based on below eBPF examples and Internet resources:

https://github.com/iovisor/bcc

https://github.com/iovisor/bcc/tree/master/examples/networking/http_filter

https://gist.github.com/sunhay/02f235f2942403fada25063242a3aeb1

ebpf-tracing-demo's People

Contributors

linhanphan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.