Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Go-based network traffic sniffer that captures, parses, and stores HTTP/HTTPS traffic data with monitoring capabilities using Prometheus and Grafana.

Notifications You must be signed in to change notification settings

Aditya26189/microservices

Repository files navigation

Microservices Network Traffic Sniffer

A Go-based network traffic sniffer that captures, parses, and stores HTTP/HTTPS traffic data with monitoring capabilities using Prometheus and Grafana.

Features

  • πŸ” 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

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Sniffer β”‚ ← Captures network packets
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
 β”‚
 ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Parser β”‚ ← Parses HTTP/TLS protocols
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
 β”‚
 ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Storage β”‚ ← Stores in MongoDB
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
 β”‚
 ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ REST API β”‚ ←→ β”‚ Grafana β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 ↑
 β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
 β”‚ Prometheus β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Prerequisites

  • Go 1.24.3 or higher
  • Docker and Docker Compose
  • libpcap (for packet capture)
    • Linux: sudo apt-get install libpcap-dev
    • macOS: brew install libpcap
    • Windows: WinPcap or Npcap

Installation

Clone the Repository

git clone https://github.com/Aditya26189/microservices.git
cd microservices

Install Dependencies

go mod download

Usage

Running with Docker Compose

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

Running Locally

  1. Start MongoDB (or use Docker):

    docker run -d -p 27017:27017 -v ./mongo-data:/data/db mongo
  2. 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.

Finding Your Network Interface

Linux:

ip link show

macOS:

ifconfig

Windows:

Get-NetAdapter

API Endpoints

The sniffer exposes a REST API (configured via gorilla/mux):

  • GET /api/events - Retrieve captured network events
  • GET /api/dependencies - Query service dependencies
  • GET /api/logs - Access stored log entries

Note: See internal/handler/handler.go for complete API documentation.

Monitoring

Prometheus

Access Prometheus at http://localhost:9090 to:

  • View captured metrics
  • Run PromQL queries
  • Monitor sniffer performance

Grafana

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/.

Project Structure

.
β”œβ”€β”€ 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

Configuration

Environment Variables

Configure the application using environment variables:

  • MONGO_URI: MongoDB connection string (default: mongodb://localhost:27017)
  • MONGO_DATABASE: Database name
  • API_PORT: REST API port (default: 8080)

MongoDB

MongoDB configuration is handled in configs/config.go. Modify connection settings as needed.

Development

Building

go build -o sniffer ./cmd/sniffer

Testing

go test ./...

Data Models

Event

Represents a captured network event with source/destination IPs, ports, protocols, and timestamps.

LogEntry

Structured log entries for captured traffic analysis.

Dependencies

Tracks inter-service communication patterns and dependencies.

See internal/model/ for complete model definitions.

Troubleshooting

Permission Denied Errors

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"

No Packets Captured

  • Verify the correct network interface with ifconfig or ip link
  • Check BPF filter syntax
  • Ensure traffic is flowing on the specified ports
  • Verify firewall settings

MongoDB Connection Issues

  • Ensure MongoDB is running: docker ps
  • Check connection string in configs/config.go
  • Verify network connectivity to MongoDB

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Contact

Aditya26189 - GitHub Profile

Project Link: https://github.com/Aditya26189/microservices

About

A Go-based network traffic sniffer that captures, parses, and stores HTTP/HTTPS traffic data with monitoring capabilities using Prometheus and Grafana.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /