eBPF网络监视器
具有HTTP API服务器的模块化eBPF监控系统,用于实时网络和系统事件监控。 支持VM和Kubernetes部署 具有自动元数据丰富功能。
🚀 部署选项
Kubernetes部署(推荐)
通过自动节点元数据丰富在整个Kubernetes集群中部署:```bash
Quick deployment with built-in script
./scripts/deploy.sh all --registry your-registry.com
Or step by step
make docker-build
make docker-push REGISTRY=your-registry.com
make k8s-deploy
**📖 完整的Kubernetes指南** -详细的设置和配置
### 带种类的本地测试
在本地测试完整的Kubernetes部署:```bash
# Full automated test
make kind-full-test
# Or step by step:
make kind-cluster-create # Create local cluster
make kind-deploy # Deploy to kind cluster
make kind-integration-test # Run comprehensive tests
获取聚合器的详细API文档,仅在Kubernetes模式下可用 请参阅API聚合器文档
VM部署(传统)
对于单服务器部署:```bash
Install dependencies (Ubuntu/Debian)
sudo apt install -y golang-go clang libbpf-dev linux-headers-$(uname -r)
Build and run
make build
sudo ./bin/ebpf-server
Test the API
curl http://localhost:8080/health
curl "http://localhost:8080/api/events?type=connection&limit=10"
**📚 交互式API文档** -在浏览器中测试API
## ✨ 主要特点
### 🔄 双重部署支持
- **Kubernetes模式**:用于集群范围监控的DaemonSet+聚合器架构
- **虚拟机模式**:传统的单服务器部署
- **自动检测**:无缝检测环境并调整行为
### 🏷️ Kubernetes元数据扩展
Kubernetes中的事件包含丰富的元数据:```json
{
"id": "abc123",
"type": "connection",
"k8s_node_name": "worker-node-1",
"k8s_pod_name": "ebpf-monitor-xyz",
"k8s_namespace": "ebpf-system",
...
}
🏗️ 可扩展体系结构
Kubernetes模式:具有集中聚合功能的分布式监控```
┌─────────────────────────────────────────────────────────┐
│ Kubernetes Cluster │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │ Node 1 │ │ Node 2 │ │ Node N │ │
│ │ ┌─────────┐ │ │ ┌─────────┐ │ │ ┌─────────┐ │ │
│ │ │ eBPF │ │ │ │ eBPF │ │ │ │ eBPF │ │ │
│ │ │ Agent │ │ │ │ Agent │ │ │ │ Agent │ │ │
│ │ │+K8s Meta│ │ │ │+K8s Meta│ │ │ │+K8s Meta│ │ │
│ │ └────┬────┘ │ │ └────┬────┘ │ │ └────┬────┘ │ │
│ └──────┼──────┘ └──────┼──────┘ └────────┼────────┘ │
│ │ │ │ │
│ └────────────────┼──────────────────┘ │
│ │ │
│ ┌─────▼─────┐ │
│ │ eBPF │ │
│ │ Aggregator│◄─── Unified API │
│ │ │ │
│ └───────────┘ │
└─────────────────────────────────────────────────────────┘
**虚拟机模式**:模块化、基于接口的监控系统```
┌─────────────────────────────────────────────────────┐
│ eBPF Programs │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Connection │ │ Packet Drop │ │ Custom │ │
│ │ Monitor │ │ Monitor │ │ Monitors │ │
│ └──────┬──────┘ └──────┬──────┘ └─────────┬───┘ │
└─────────┼─────────────────┼──────────────────┼-─────┘
│ │ │
└─────────────────┼──────────────────┘
▼
┌─────────────────────────┐
│ Event Processing │
│ (Manager + Storage) │
└─────────────┬───────────┘
▼
┌─────────────────────────┐
│ HTTP API │
│ (/api/events) │
└─────────────────────────┘
📊 统一监控
- 交叉节点相关性:查看整个Kubernetes集群中的事件
- 节点特定筛选:按特定节点或Pod查询事件
- 汇总统计数据:集群范围内的事件统计和指标
- 向后兼容:现有VM部署继续保持不变
📡 API功能
- 统一事件API:单人
/api/events所有监控数据的端点 - 灵活过滤:按事件类型、PID、命令和时间窗口筛选
- Kubernetes过滤:按节点名称、pod名称或命名空间筛选
- 程序状态:通过查看程序状态和指标
/api/programs - 自动生成的文档:代码注释中的OpenAPI 3.0规范
- 交互式测试:用于API勘探的内置Swagger UI
核心终点
GET /health-系统健康和状态GET /api/events-查询支持过滤的事件GET /api/programs-列出所有程序及其状态
查询示例```bash
Get all connection events from the last hour
curl "http://localhost:8080/api/events?type=connection&since=2023-01-01T00:00:00Z"
Get events for a specific process
curl "http://localhost:8080/api/events?pid=1234&limit=50"
Kubernetes: Get events from specific node
curl "http://localhost:8080/api/events?k8s_node_name=worker-1"
### 查询参数
- `type`:事件类型过滤器(例如,“connection”、“packet_drop”)
- `pid`:进程ID筛选器
- `command`:命令名称筛选器
- `k8s_node_name`, `k8s_pod_name`, `k8s_namespace`:Kubernetes过滤器
- `since`, `until`:RFC3339时间戳过滤器
- `limit`:最大结果(默认值:100)
## 🛠️ 发展```bash
# Development build with debug logging
make build-dev && sudo ./bin/ebpf-server-dev
# Generate API docs
make docs
# Run tests
make test
# Build eBPF programs
make build-bpf
📚 完整开发指南 -创建新eBPF监控程序的详细指南
📁 项目结构```
├── cmd/ # Application entry points
│ ├── server/ # eBPF monitoring server
│ └── aggregator/ # Kubernetes aggregator
├── internal/
│ ├── core/ # Core interfaces and types
│ ├── events/ # Event system (BaseEvent, streams)
│ ├── programs/ # eBPF program implementations
│ ├── storage/ # Event storage and querying
│ ├── api/ # HTTP API handlers
│ ├── kubernetes/ # Kubernetes metadata integration
│ └── system/ # System initialization
├── bpf/ # eBPF C programs and headers
├── kubernetes/ # Kubernetes manifests
├── scripts/ # Deployment and testing scripts
└── docs/ # Documentation and API specs
```
🔧 需求
- Linux内核4.18+ 支持eBPF
- Root权限 用于eBPF程序加载
- 依赖项:Go 1.23+、Clang、libbpf-dev、内核头文件
- 库贝内特斯:1.20+(适用于K8s部署)
📖 安装指南: docs/setup.md
📄 许可证
MIT许可证-请参阅 许可证 文件。
