A network traffic monitoring tool for Kubernetes clusters that captures and logs network packets, providing detailed information about network connections between pods.
- Captures network packets using libpcap
- Identifies Kubernetes pods by IP address
- Supports both TCP and UDP protocols
- Provides real-time logging of network connections
- JSON output format for easy parsing
- Prometheus metrics for monitoring and alerting
- Go 1.21 or later
- libpcap development files
- Kubernetes cluster access
- Redis (optional, for caching ovn-fip information)
- Clone the repository:
git clone https://github.com/yourusername/netlog.git
cd netlog- Install dependencies:
go mod download- Build the binary:
go build -o netlog cmd/netlog/main.goOn Ubuntu/Debian:
sudo apt-get install libpcap-devOn macOS:
brew install libpcapRun NetLog with default settings:
sudo ./netlog--interface: Network interface to capture packets from (default: "eth0")--redis-addr: Redis server address (default: "localhost:6379")--redis-password: Redis password (optional)--redis-db: Redis database number (default: 0)--json: Enable JSON output format--metrics-addr: Address to expose Prometheus metrics (default: ":9090")
NetLog exposes the following Prometheus metrics at the /metrics endpoint:
netlog_network_bytes_total: Total bytes transferred- Labels: namespace, name, source, destination, protocol, port, direction
netlog_network_packets_total: Total number of packets- Labels: namespace, name, source, destination, protocol, port, direction
netlog_network_connections_active: Number of active connections- Labels: namespace, name, source, destination, protocol, port
netlog_network_connection_duration_seconds: Duration of connections- Labels: namespace, name, source, destination, protocol, port
Example Prometheus queries:
# Total bytes transferred by namespace
sum(netlog_network_bytes_total) by (namespace)
# Active connections by pod
sum(netlog_network_connections_active) by (namespace, name)
# Average connection duration
rate(netlog_network_connection_duration_seconds_sum[5m]) / rate(netlog_network_connection_duration_seconds_count[5m])
[2024-02-14 12:34:56] namespace: default, name: nginx-7f9f9f9f9f, source: 10.244.1.2:80, destination: 10.244.2.3:443, protocol: TCP, bytes: 1234, packets: 10
{
"timestamp": "2024-02-14T12:34:56Z",
"namespace": "default",
"name": "nginx-7f9f9f9f9f",
"source": "10.244.1.2:80",
"destination": "10.244.2.3:443",
"protocol": "TCP",
"bytes": 1234,
"packets": 10
}- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some 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.