This project provides a comprehensive system for monitoring and optimizing network traffic. It includes tools for capturing network traffic, analyzing it, and optimizing traffic flow using HAProxy. Performance is monitored with Prometheus and Grafana.
- Clone the Repository
git clone https://github.com/manish3173/TrafficGuard.git cd TrafficGuard - Install Monitoring Tools
sudo apt update sudo apt install tcpdump -y
- Install Analysis Tools
sudo apt install python3-pip -y pip3 install scapy prometheus-client psutil
- Install Optimization Tools
sudo apt install haproxy -y cp config/haproxy.cfg /etc/haproxy/haproxy.cfg sudo systemctl restart haproxy
- Install Reporting Tools
# Install Prometheus wget https://github.com/prometheus/prometheus/releases/download/v2.43.0/prometheus-2.43.0.linux-amd64.tar.gz tar xvf prometheus-2.43.0.linux-amd64.tar.gz mv prometheus-2.43.0.linux-amd64 /opt/prometheus # Install Grafana sudo apt update sudo apt install -y software-properties-common sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" sudo apt update sudo apt install grafana -y sudo systemctl start grafana-server
- Capture Traffic
sudo python3 src/capture_traffic.py --interface enp0s3 --duration 300 --output pcaps/capture_manual.pcap --filter "not port 22" - Analyze Captured Traffic
sudo python3 src/analyze_traffic.py pcaps/capture_manual.pcap
- Start Metrics Server
sudo python3 src/metrics_server.py --port 8000 --destinations 8.8.8.8,1.1.1.1
- Start Prometheus
sudo prometheus --config.file=config/prometheus.yml --storage.tsdb.path=prometheus_data
- Access Monitoring Interfaces
- Metrics Server: http://localhost:8000
- Prometheus: http://localhost:9090
- HAProxy Stats: http://localhost:8404/stats (username: admin, password: adminpassword)
Edit config/haproxy.cfg to:
- Add backend servers if needed
- Modify load balancing algorithms as required
- Configure health checks
- Set security parameters
Modify config/prometheus.yml to:
- Add additional monitoring targets if you want more servers
- Configure alerting rules
- Adjust scraping intervals
- Log in to Grafana at http://localhost:3000.
- Go to the Configuration (gear icon) > Data Sources > Add data source.
- Search for Prometheus, select it, and configure:
- Name: Prometheus
- URL: http://localhost:9090
- Access: Browser
- Scrape Interval: 15s
- Click Save & Test to verify the connection.
- Click the "+" icon in the sidebar and select Dashboard.
- Click Add new panel.
- In the Metrics tab, click Add query.
- Select the Prometheus data source and enter a PromQL query to visualize your metrics.
Feel free to submit issues and pull requests. Contributions are welcome!
For questions or support, please contact:
- Y Manish Kumar: ymanishk602@gmail.com
This project is licensed under the MIT License.