Skip to content

Commit ec643bb

Browse files
committed
add EF migrations for sniffy database and development instruction
1 parent 2016097 commit ec643bb

16 files changed

Lines changed: 1092 additions & 12 deletions

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,102 @@ Monitoring network packets, the Sniffy tool aggregates the data to see communica
99
Every 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.

frontend/apps/main/src/app/app.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const appRoutes: Route[] = [
44
{
55
path: '',
66
pathMatch: 'full',
7-
redirectTo: 'aframe-sample-1',
7+
redirectTo: 'force-graph-sample-1',
88
},
99
{
1010
path: 'threejs-sample',

sniffy-webapi/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ ClientBin/
9999

100100
*.publishsettings
101101

102+
.idea/
103+
102104
# RIA/Silverlight projects
103105
Generated_Code/
104106

sniffy-webapi/Ycode.Sniffy.Domain/Migrations/20241125110904_initial.Designer.cs

Lines changed: 248 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace Ycode.Sniffy.Domain.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class initial : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
14+
}
15+
16+
/// <inheritdoc />
17+
protected override void Down(MigrationBuilder migrationBuilder)
18+
{
19+
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)