@@ -9,3 +9,102 @@ Monitoring network packets, the Sniffy tool aggregates the data to see communica
99Every network endpoint in the diagram has an IP address and communication protocols are connected in thick lines. The protocols are displayed with their significant port number.
1010
1111![ Sniffy Network Traffic] ( https://github.com/y-code/pcap-sample/raw/main/docs/img/sniffy-network-traffic.gif )
12+
13+ ## Development
14+
15+ ### 1. Build Custom Kafka Connect Sink
16+
17+ This Kafka Connect Sink reads the sniffy protobuf data from a topic and store it in the PostgreSQL database.
18+
19+ Build it with the command below.
20+
21+ ```
22+ docker run --rm -it --name java-dev -v $HOME/.m2/:/root/.m2/ -v $REPO_ROOT:/tmp/ -w /tmp/kafka-connect-sink maven:3.9.9-amazoncorretto-8-debian bash -c "apt-get update -y && apt-get install -y protobuf-compiler && mvn clean package"
23+ ```
24+
25+ ### 2. Build Kafka Connect Docker Image
26+
27+ To pre-install Kafka Connect's JDBC library using ` confluent-hub ` utility, build a custom Kafka Connect docker image.
28+
29+ ```
30+ docker build -t ycode/kafka-connect:7.6.1 -f ./ypcap-middleware/kafka-connect/Dockerfile .
31+ ```
32+
33+ The docker image tag name can be whatever, but it just needs to match the kafka-connect service's image tag in the docker-compose.yml.
34+
35+ ### 3. Run Docker Containers
36+
37+ Let's run four required docker containers by docker compose. It will start Kafka, Kafka Connect, Kafdrop, and PostgreSQL servers in the containers.
38+
39+ ```
40+ docker compose --project-directory ./ypcap-middleware up -d
41+ ```
42+
43+ ### 4. Initialize Database
44+
45+ To create the ` sniffy ` database and tables in it, run the following Entity Framework command.
46+
47+ ```
48+ dotnet ef database update --project ./sniffy-webapi/Ycode.Sniffy.Domain
49+ ```
50+
51+ NOTE: The Kafka Connect Sink can also create the required table, but it cannot create the database.
52+
53+ ### 5. Install Protobuf Compiler
54+
55+ ```
56+ apt-get install protobuf-compiler
57+ ```
58+ or
59+ ```
60+ brew install protobuf
61+ ```
62+
63+ ### 6. Build Sniffy
64+
65+ ```
66+ cmake -B build
67+ cmake --build build
68+ ```
69+
70+ ### 7. Run Sniffy
71+
72+ Now, it is ready to run Sniffy agent.
73+
74+ ```
75+ sudo ./build/sniffy | ./build/traffic-aggry -k -v
76+ ```
77+
78+ The summary of the data sent to the Kafka topic can be monitored on Kafdrop http://localhost:9000/topic/traffic .
79+
80+ ### 8. Install PLpgSQL Stored Procedure for Data Analysis with Apache AGE
81+
82+ ```
83+ docker exec -it postgresql psql -U postgres -d sniffy -a -f /var/lib/postgresql/data/ddl/init.sql
84+ docker exec -it postgresql psql -U postgres -d sniffy -a -f /var/lib/postgresql/data/ddl/create_graph_from_table.sql
85+ ```
86+
87+ ### 9. Run Data Analysis with Apache AGE
88+
89+ ```
90+ docker exec -it postgresql psql -U postgres -d sniffy -a -c "SET search_path = ag_catalog, \"\$user\", public; CALL create_graph_from_table('graph_1', 'traffic_metrics');"
91+ ```
92+
93+ ` graph_1 ` can be modified, but it should match ` GraphSchema ` in ` sniffy-webapi/Ycode.Sniffy.WebApi/appsettings.json ` file.
94+
95+ ### 10. Run Web Services for Visualization with Three.js
96+
97+ Run the backend first.
98+
99+ ```
100+ dotnet run --project ./sniffy-webapi/Ycode.Sniffy.WebApi
101+ ```
102+
103+ In another terminal, run the frontend development server.
104+
105+ ```
106+ cd $REPO_ROOT/frontend
107+ npx nx serve main
108+ ```
109+
110+ Now, open http://localhost:4200/ on browser.
0 commit comments