Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import flow package in init.go to enable flow probe #112

Merged
merged 4 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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