Skip to content

Commit

Permalink
Merge pull request alibaba#112 from jzwlqx/flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyt99 committed Oct 7, 2023
2 parents 1bc1dc6 + ad9b21b commit 14e1bf3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/exporter/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/flow"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/nlconntrack"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/nlqdisc"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/procfd"
Expand Down
31 changes: 23 additions & 8 deletions pkg/exporter/probe/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,32 @@ func (p *metricsProbe) collectOnce(emit probe.Emit) error {
val.Bytes += values[i].Bytes
val.Packets += values[i].Packets
}
emit("bytes", []string{}, float64(val.Bytes))
emit("packets", []string{}, float64(val.Packets))

fmt.Printf("proto: %d %s:%d->%s:%d pkts: %d, bytes: %d\n",
key.Proto,
var protocol string

switch key.Proto {
case 1:
protocol = "icmp"
case 6:
protocol = "tcp"
case 17:
protocol = "udp"
case 132:
protocol = "sctp"
default:
log.Errorf("%s unknown ip protocol number %d", probeName, key.Proto)
}

labels := []string{
protocol,
toIPString(key.Src),
htons(key.Sport),
toIPString(key.Dst),
htons(key.Dport),
val.Packets,
val.Bytes)
fmt.Sprintf("%d", htons(key.Sport)),
fmt.Sprintf("%d", htons(key.Dport)),
}

emit("bytes", labels, float64(val.Bytes))
emit("packets", labels, float64(val.Packets))
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ func (b *BatchMetrics) Collect(metrics chan<- prometheus.Metric) {
log.Errorf("%s undeclared metrics %s", b.name, name)
return
}
metrics <- prometheus.MustNewConstMetric(info.desc, info.valueType, val, labels...)
m, err := prometheus.NewConstMetric(info.desc, info.valueType, val, labels...)
if err != nil {
log.Errorf("%s failed create metrics, err: %v", b.name, err)
return
}
metrics <- m
}

err := b.ProbeCollector(emit)
Expand Down

0 comments on commit 14e1bf3

Please sign in to comment.