Skip to content

Commit

Permalink
more work in progress for more subcollectors
Browse files Browse the repository at this point in the history
Signed-off-by: Francis Begyn <[email protected]>
  • Loading branch information
fbegyn committed Oct 13, 2024
1 parent 46d1a88 commit 752964d
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 295 deletions.
17 changes: 14 additions & 3 deletions cmd/tc_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,27 @@ func main() {
// registering application information
prometheus.MustRegister(NewVersionCollector("tc_exporter"))

// fetch all the interfaces from the configured network namespaces
// and store them in a map
netns := make(map[string][]rtnetlink.LinkMessage)
for ns, sp := range cf.NetNS {
interfaces, err := getInterfaceInNS(sp.Interfaces, ns)
interfaces, err := getInterfacesInNetNS(sp.Interfaces, ns)
if err != nil {
logger.Error("failed to get interfaces from ns", "err", err, "netns", ns)
}
netns[ns] = interfaces
}

collector, err := tcexporter.NewTcCollector(netns, logger)
enabledCollectors := map[string]bool{
"hfsc": true,
"fq": true,
"fqcodel": true,
"hfscq": true,
"htb": true,
}

// initialise the collector with the configured subcollectors
collector, err := tcexporter.NewTcCollector(netns, enabledCollectors, logger)
if err != nil {
logger.Error("msg", "failed to create TC collector", "err", err)
}
Expand All @@ -92,7 +103,7 @@ func main() {
}
}

func getInterfaceInNS(devices []string, ns string) ([]rtnetlink.LinkMessage, error) {
func getInterfacesInNetNS(devices []string, ns string) ([]rtnetlink.LinkMessage, error) {
con, err := tcexporter.GetNetlinkConn(ns)
if err != nil {
return nil, err
Expand Down
77 changes: 76 additions & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type TcCollector struct {
}

// NewTcCollector create a new TcCollector given a network interface
func NewTcCollector(netns map[string][]rtnetlink.LinkMessage, logger *slog.Logger) (prometheus.Collector, error) {
func NewTcCollector(netns map[string][]rtnetlink.LinkMessage, collectorEnables map[string]bool, logger *slog.Logger) (prometheus.Collector, error) {
collectors := []prometheus.Collector{}

// Setup Qdisc collector for interface
qColl, err := NewQdiscCollector(netns, logger)
if err != nil {
Expand All @@ -38,6 +39,80 @@ func NewTcCollector(netns map[string][]rtnetlink.LinkMessage, logger *slog.Logge
}
collectors = append(collectors, scColl)

// add additional collectors
for collector, enabled := range collectorEnables {
if enabled {
switch collector {
case "cbq":
coll, err := NewCBQCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "choke":
coll, err := NewChokeCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "codel":
coll, err := NewCodelCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "fq":
coll, err := NewFqCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "fq_codel":
coll, err := NewFqCodelCollector()(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "hfsc":
coll, err := NewHfscCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "htb":
coll, err := NewHTBCollector()(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "pie":
coll, err := NewPieCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "red":
coll, err := NewRedCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "sfb":
coll, err := NewSFBCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
case "sfq":
coll, err := NewSFQCollector(netns, logger)
if err != nil {
return nil, err
}
collectors = append(collectors, coll)
}
}
}

return &TcCollector{
logger: *logger,
netns: netns,
Expand Down
Loading

0 comments on commit 752964d

Please sign in to comment.