Skip to content

Commit cee5c12

Browse files
committed
feat: add eBPF plugin
1 parent 4de08ca commit cee5c12

17 files changed

+5208
-4
lines changed

agent/metrics_agent.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
_ "flashcat.cloud/categraf/inputs/diskio"
2929
_ "flashcat.cloud/categraf/inputs/dns_query"
3030
_ "flashcat.cloud/categraf/inputs/docker"
31+
_ "flashcat.cloud/categraf/inputs/eBPF"
3132
_ "flashcat.cloud/categraf/inputs/elasticsearch"
3233
_ "flashcat.cloud/categraf/inputs/exec"
3334
_ "flashcat.cloud/categraf/inputs/filecount"
@@ -37,6 +38,7 @@ import (
3738
_ "flashcat.cloud/categraf/inputs/http_response"
3839
_ "flashcat.cloud/categraf/inputs/influxdb"
3940
_ "flashcat.cloud/categraf/inputs/ipmi"
41+
_ "flashcat.cloud/categraf/inputs/iptables"
4042
_ "flashcat.cloud/categraf/inputs/ipvs"
4143
_ "flashcat.cloud/categraf/inputs/jenkins"
4244
_ "flashcat.cloud/categraf/inputs/jolokia_agent"
@@ -92,7 +94,6 @@ import (
9294
_ "flashcat.cloud/categraf/inputs/whois"
9395
_ "flashcat.cloud/categraf/inputs/xskyapi"
9496
_ "flashcat.cloud/categraf/inputs/zookeeper"
95-
_ "flashcat.cloud/categraf/inputs/iptables"
9697
)
9798

9899
type MetricsAgent struct {

conf/input.eBPF/eBPF.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# # collect interval
2+
# interval = 15
3+
[[instances]]
4+
interface = "ens38"
5+
6+
[[instances]]
7+
interface = "ens33"

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ require (
7979
github.com/clbanning/mxj/v2 v2.5.5 // indirect
8080
github.com/dennwc/ioctl v1.0.0 // indirect
8181
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
82-
github.com/frankban/quicktest v1.14.3 // indirect
8382
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
8483
github.com/go-asn1-ber/asn1-ber v1.5.5 // indirect
8584
github.com/goccy/go-json v0.10.2 // indirect
@@ -138,6 +137,7 @@ require (
138137
github.com/bits-and-blooms/bitset v1.13.0
139138
github.com/blang/semver/v4 v4.0.0
140139
github.com/bmatcuk/doublestar/v3 v3.0.0
140+
github.com/cilium/ebpf v0.12.3
141141
github.com/coreos/go-systemd/v22 v22.5.0
142142
github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1
143143
github.com/ema/qdisc v1.0.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHqu
299299
github.com/frankban/quicktest v1.11.0/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
300300
github.com/frankban/quicktest v1.11.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
301301
github.com/frankban/quicktest v1.13.0/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU=
302-
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
303-
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
302+
github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA=
303+
github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
304304
github.com/freedomkk-qfeng/go-fastping v0.0.0-20160109021039-d7bb493dee3e h1:g8x+P3+xjxt7c53bucQW0ymvj+whjKfCLZH+99UMLS0=
305305
github.com/freedomkk-qfeng/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:UcrAEbxjAhuq5beDj0conKRHGUhBPLkFt8aUmN/jrHY=
306306
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=

inputs/eBPF/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# eBPF
2+
3+
利用ebpf和xdp技术进行网络数据采集
4+
5+
目前插件逻辑为在XDP挂载点采集RoCE网络数据,仅需设置网卡名称
6+
后续可自定义更强大的功能
7+
## 环境要求
8+
本插件利用cilium提供的eBPF-go库,需要先配置eBPF环境,详细请参考[教程](https://ebpf-go.dev/guides/getting-started/),在Linux内核版本较低的机器上可能无法部署
9+
10+
在部署后可通过以下指令生成脚手架代码
11+
```
12+
go generate inputs/eBPF/eBPF.go
13+
14+
Compiled /home/xxx/categraf/inputs/eBPF/bpf_bpfel.o
15+
Stripped /home/xxx/categraf/inputs/eBPF/bpf_bpfel.o
16+
Wrote /home/xxx/categraf/inputs/eBPF/bpf_bpfel.go
17+
Compiled /home/xxx/categraf/inputs/eBPF/bpf_bpfeb.o
18+
Stripped /home/xxx/categraf/inputs/eBPF/bpf_bpfeb.o
19+
Wrote /home/xxx/categraf/inputs/eBPF/bpf_bpfeb.go
20+
```
21+
利用以上脚手架代码进行eBPF相关操作

inputs/eBPF/bpf_bpfeb.go

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inputs/eBPF/bpf_bpfeb.o

3.81 KB
Binary file not shown.

inputs/eBPF/bpf_bpfel.go

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inputs/eBPF/bpf_bpfel.o

3.85 KB
Binary file not shown.

0 commit comments

Comments
 (0)