Skip to content

Commit

Permalink
Merge pull request #29 from wide-vsix/dev
Browse files Browse the repository at this point in the history
Metrics Exporter Improvement
  • Loading branch information
slankdev authored Nov 9, 2022
2 parents 982e6a8 + 23622d1 commit 53c1edd
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 174 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ REFS
- [Packet mark in a Cloud Native world, LPC](https://lpc.events/event/7/contributions/683/attachments/554/979/lpc20-pkt-mark-slides.pdf)
- [VMware NSX IPFIX for Distributed Firewall](https://docs.vmware.com/en/VMware-NSX-Data-Center-for-vSphere/6.4/com.vmware.nsx.admin.doc/GUID-2C625B52-17F0-4604-B5C9-6DF1FA9A70F8.html)
- [VMware NSX IPFIX for Logical Switch](https://docs.vmware.com/en/VMware-NSX-Data-Center-for-vSphere/6.4/com.vmware.nsx.admin.doc/GUID-6054CF07-3019-4539-A6CC-1F613E275E27.html)
- [Comparison and Practice of packet processing implementations and acceleration methods (ja), Ebiken-san, Higebu-san, JANOG45](https://www.janog.gr.jp/meeting/janog45/program/pktfwd/)
- [IN-kernel metadata propagation technique from XDP buffer to SKB](https://github.com/torvalds/linux/blob/master/samples/bpf/xdp2skb_meta_kern.c)
- [Private Discussion for metadata practice in eBPF](https://netmoles.slack.com/archives/C01DYBEETN0/p1667363998874089)
- [One of the Reference design for traffic control mech using eBPF(both xdp and tc), ENOG63 by Higebu-san](https://www.docswell.com/s/higebu/ZQWRMZ-xdp-based-mobile-network-data-plane#p21)

## Specification

Expand Down
23 changes: 15 additions & 8 deletions pkg/ebpfmap/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,34 @@ func GetMapIDsByNameType(mapName string, mapType ebpf.MapType) ([]ebpf.MapID, er
return ids, nil
}

type StatsMetricsKey struct {
IngressIfindex uint32 `json:"ingress_ifindex"`
EgressIfindex uint32 `json:"egress_ifindex"`
}

type StatsMetricsVal struct {
SynPkts uint32 `json:"syn_pkts"`
OverflowPkts uint32 `json:"overflow_pkts"`
OverflowBytes uint32 `json:"overflow_bytes"`
TotalPkts uint32 `json:"total_pkts"`
TotalBytes uint32 `json:"total_bytes"`
SynPkts uint32 `json:"syn_pkts"`
TotalPkts uint32 `json:"total_pkts"`
TotalBytes uint32 `json:"total_bytes"`
OverflowPkts uint32 `json:"overflow_pkts"`
OverflowBytes uint32 `json:"overflow_bytes"`
TotalLatencyNanoseconds uint32 `json:"latency_nano_sum"`
}

func GetStats() (map[uint32]StatsMetricsVal, error) {
func GetStats() (map[StatsMetricsKey]StatsMetricsVal, error) {
ids, err := GetMapIDsByNameType(metricsMapName, metricsMapType)
if err != nil {
return nil, err
}

ret := map[uint32]StatsMetricsVal{}
ret := map[StatsMetricsKey]StatsMetricsVal{}
for _, id := range ids {
m, err := ebpf.NewMapFromID(id)
if err != nil {
return nil, err
}

var key uint32
key := StatsMetricsKey{}
perCpuVals := []StatsMetricsVal{}
entries := m.Iterate()
for entries.Next(&key, &perCpuVals) {
Expand All @@ -152,6 +158,7 @@ func GetStats() (map[uint32]StatsMetricsVal, error) {
val.OverflowBytes += perCpuVal.OverflowBytes
val.TotalPkts += perCpuVal.TotalPkts
val.TotalBytes += perCpuVal.TotalBytes
val.TotalLatencyNanoseconds += perCpuVal.TotalLatencyNanoseconds
}
ret[key] = val
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/flowctl/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ func NewCommandEbpfCodeDump() *cobra.Command {
return cmd
}

func getTcEbpfByteCode(netns, dev string) (string, error) {
func getTcEbpfByteCode(netns, dev, direction string) (string, error) {
clsActIsEnabled, err := goroute2.ClsActIsEnabled(netns, dev)
if err != nil {
return "", err
}
if clsActIsEnabled {
rules, err := goroute2.ListTcFilterRules(netns, dev)
rules, err := goroute2.ListTcFilterRules(netns, dev, direction)
if err != nil {
return "", err
}
Expand All @@ -182,8 +182,8 @@ func getTcEbpfByteCode(netns, dev string) (string, error) {
return "", nil
}

func getFlowMeterByteCode(netns, dev string) (*FlowMeterByteCode, error) {
bpfname, err := getTcEbpfByteCode(netns, dev)
func getFlowMeterByteCode(netns, dev, dir string) (*FlowMeterByteCode, error) {
bpfname, err := getTcEbpfByteCode(netns, dev, dir)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 53c1edd

Please sign in to comment.