Skip to content

Commit

Permalink
Collect clients per VLAN
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed May 31, 2024
1 parent 1c0abc8 commit 3469e84
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
27 changes: 26 additions & 1 deletion wireless/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"

"github.com/slashdoom/aruba_exporter/rpc"
Expand Down Expand Up @@ -153,4 +154,28 @@ func (c *wirelessCollector) ParseRadios(ostype string, radios map[string]Wireles
log.Tracef("output: %s\n", output)

return make(map[string]WirelessRadio), nil
}
}

var (
apVLANUsageLineRegex = regexp.MustCompile(`^(\d+)\s+(\d+)$`)
)

func parseAPVLANUsage(output string) map[int]int {
lines := strings.Split(output, "\n")
results := make(map[int]int, len(lines))
for _, line := range lines {
matches := apVLANUsageLineRegex.FindStringSubmatch(line)
if len(matches) == 3 {
vlan, err := strconv.Atoi(matches[1])
if err != nil {
continue
}
clients, err := strconv.Atoi(matches[2])
if err != nil {
continue
}
results[vlan] = clients
}
}
return results
}
25 changes: 18 additions & 7 deletions wireless/wireless_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wireless
import (
"errors"
"fmt"
"strconv"

"github.com/slashdoom/aruba_exporter/collector"
"github.com/slashdoom/aruba_exporter/rpc"
Expand All @@ -14,9 +15,10 @@ import (
const prefix string = "aruba_wireless_"

var (
apUp *prometheus.Desc
apController *prometheus.Desc
apClients *prometheus.Desc
apUp *prometheus.Desc
apController *prometheus.Desc
apClients *prometheus.Desc
apConnectedClients *prometheus.Desc

channelNoiseDesc *prometheus.Desc
channelUtilDesc *prometheus.Desc
Expand All @@ -30,6 +32,7 @@ func init() {
apUp = prometheus.NewDesc(prefix+"ap_up", "Scrape of AP was successful", l, nil)
apController = prometheus.NewDesc(prefix+"ap_controller", "AP is Virtual Controller", l, nil)
apClients = prometheus.NewDesc(prefix+"ap_clients", "AP Connected Clients ", l, nil)
apConnectedClients = prometheus.NewDesc(prefix+"ap_connected_clients", "Connected Clients per VLAN", []string{"target", "vlan_id"}, nil)
l = []string{"target", "ap", "channel", "band"}
channelNoiseDesc = prometheus.NewDesc(prefix+"channel_noise", "Channel Noise", l, nil)
channelUtilDesc = prometheus.NewDesc(prefix+"channel_utilization", "Channel Utilization", l, nil)
Expand All @@ -56,6 +59,7 @@ func (*wirelessCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- apUp
ch <- apController
ch <- apClients
ch <- apConnectedClients

ch <- channelNoiseDesc
ch <- channelUtilDesc
Expand Down Expand Up @@ -109,20 +113,23 @@ func (c *wirelessCollector) CollectAccessPoints(client *rpc.Client, ch chan<- pr
return aps, nil
}

func (c *wirelessCollector) CollectVLANUsage(client *rpc.Client, ch chan<- prometheus.Metric) error {
func (c *wirelessCollector) CollectVLANUsage(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error {
out, err := client.RunCommand([]string{"show ap vlan-usage"})
if err != nil {
return err
}

stats := parseAPVLANUsage(out)
log.Debugf("vlan usage: %#v", stats)
log.Debugf("vlan clients: %#v", stats)
for vlan, clients := range stats {
labels := make([]string, 0, len(labelValues)+1)
labels = append(labels, labelValues...)
labels = append(labels, strconv.Itoa(vlan))
ch <- prometheus.MustNewConstMetric(
apVLANUsageDesc,
apConnectedClients,
prometheus.GaugeValue,
float64(clients),
strconv.Itoa(vlan),
labels...,
)
}

Expand Down Expand Up @@ -230,5 +237,9 @@ func (c *wirelessCollector) Collect(client *rpc.Client, ch chan<- prometheus.Met
}
log.Debugf("radios: %+v", radios)

if err := c.CollectVLANUsage(client, ch, labelValues); err != nil {
log.WithError(err).Error("CollectVLANUsage failed")
}

return nil
}

0 comments on commit 3469e84

Please sign in to comment.