A Go-based network traffic sniffer that captures, parses, and stores HTTP/HTTPS traffic data with monitoring capabilities using Prometheus and Grafana.
- π Network Traffic Capture: Real-time packet sniffing using
gopacket - π HTTP/HTTPS Protocol Support: Parses HTTP and TLS traffic on configurable ports
- πΎ MongoDB Storage: Persists captured traffic data and service dependencies
- π Monitoring: Integrated with Prometheus and Grafana for metrics visualization
- π³ Docker Support: Fully containerized setup with Docker Compose
- π REST API: Query captured traffic and service dependencies
βββββββββββββββ
β Sniffer β β Captures network packets
ββββββββ¬βββββββ
β
β
βββββββββββββββ
β Parser β β Parses HTTP/TLS protocols
ββββββββ¬βββββββ
β
β
βββββββββββββββ
β Storage β β Stores in MongoDB
ββββββββ¬βββββββ
β
β
βββββββββββββββ βββββββββββββββ
β REST API β ββ β Grafana β
βββββββββββββββ βββββββββββββββ
β
β
ββββββββ΄βββββββ
β Prometheus β
βββββββββββββββ
- Go 1.24.3 or higher
- Docker and Docker Compose
- libpcap (for packet capture)
git clone https://github.com/Aditya26189/microservices.git
cd microservicesgo mod download
The easiest way to run the entire stack:
docker-compose up -d
This will start:
- MongoDB on port
27017 - Prometheus on port
9090 - Grafana on port
3000 - Sniffer service with packet capture capabilities
-
Start MongoDB (or use Docker):
docker run -d -p 27017:27017 -v ./mongo-data:/data/db mongo
-
Run the Sniffer:
go run ./cmd/sniffer/main.go -iface <network-interface> -ports "80 or 443" -snaplen 1600 -timeout 30
Parameters:
-iface: Network interface to capture from (e.g.,eth0,en0,Wi-Fi)-ports: BPF port filter (default:"80 or 443")-snaplen: Snap length for packet capture (default:1600)-timeout: Timeout in seconds (default:30)
Example:
# Linux/macOS sudo go run ./cmd/sniffer/main.go -iface eth0 -ports "80 or 443 or 8080" # Windows go run ./cmd/sniffer/main.go -iface "Ethernet" -ports "80 or 443"
Note: Root/admin privileges may be required for packet capture.
Linux:
ip link show
macOS:
ifconfig
Windows:
Get-NetAdapterThe sniffer exposes a REST API (configured via gorilla/mux):
GET /api/events- Retrieve captured network eventsGET /api/dependencies- Query service dependenciesGET /api/logs- Access stored log entries
Note: See
internal/handler/handler.gofor complete API documentation.
Access Prometheus at http://localhost:9090 to:
- View captured metrics
- Run PromQL queries
- Monitor sniffer performance
Access Grafana at http://localhost:3000 (default credentials: admin/admin) to:
- Visualize traffic patterns
- Create custom dashboards
- Set up alerts
Pre-configured dashboards are available in deployments/grafana/dashboards/.
.
βββ cmd/
β βββ sniffer/ # Main application entry point
βββ configs/ # Configuration management
βββ internal/
β βββ capture/ # Packet capture logic
β βββ db/ # Database connections
β βββ handler/ # HTTP API handlers
β βββ logging/ # Logging utilities
β βββ model/ # Data models
β βββ parser/ # Protocol parsers (HTTP, TLS)
β βββ storage/ # Storage layer
β βββ utils/ # Utility functions
βββ deployments/
β βββ Dockerfile.sniffer
β βββ prometheus.yml
β βββ grafana/ # Grafana provisioning
βββ docs/ # Documentation
βββ mongo-data/ # MongoDB data directory
βββ docker-compose.yml
Configure the application using environment variables:
MONGO_URI: MongoDB connection string (default:mongodb://localhost:27017)MONGO_DATABASE: Database nameAPI_PORT: REST API port (default:8080)
MongoDB configuration is handled in configs/config.go. Modify connection settings as needed.
go build -o sniffer ./cmd/sniffer
go test ./...Represents a captured network event with source/destination IPs, ports, protocols, and timestamps.
Structured log entries for captured traffic analysis.
Tracks inter-service communication patterns and dependencies.
See internal/model/ for complete model definitions.
Packet capture requires elevated privileges:
# Linux/macOS sudo go run ./cmd/sniffer/main.go -iface eth0 # Windows (run as Administrator) go run ./cmd/sniffer/main.go -iface "Ethernet"
- Verify the correct network interface with
ifconfigorip link - Check BPF filter syntax
- Ensure traffic is flowing on the specified ports
- Verify firewall settings
- Ensure MongoDB is running:
docker ps - Check connection string in
configs/config.go - Verify network connectivity to MongoDB
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- gopacket - Packet processing library
- MongoDB Go Driver - MongoDB client
- Gorilla Mux - HTTP router
- Prometheus - Monitoring system
- Grafana - Analytics platform
Aditya26189 - GitHub Profile
Project Link: https://github.com/Aditya26189/microservices