From ee7e1806e2a66e45d6e25e3bcc395e98f11b6f55 Mon Sep 17 00:00:00 2001 From: nyyu Date: Sat, 4 Mar 2023 22:44:07 +0100 Subject: [PATCH] feat: add ipv4_port_range --- collector.go | 8 ++++++-- fbx/get_metrics.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/collector.go b/collector.go index 8e71db5..f7a9d97 100644 --- a/collector.go +++ b/collector.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" "sync" + "fmt" "github.com/prometheus/client_golang/prometheus" "github.com/trazfr/freebox-exporter/fbx" @@ -24,7 +25,7 @@ var ( promDescInfo = prometheus.NewDesc( metricPrefix+"info", "constant metric with value=1. Various information about the Freebox", - []string{"firmware", "mac", "serial", "boardname", "box_flavor", "connection_type", "connection_state", "connection_media", "ipv4", "ipv6"}, nil) + []string{"firmware", "mac", "serial", "boardname", "box_flavor", "connection_type", "connection_state", "connection_media", "ipv4", "ipv6", "ipv4_port_range"}, nil) promDescSystemUptime = prometheus.NewDesc( metricPrefix+"system_uptime", @@ -240,6 +241,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { var cnxMedia string var cnxIPv4 string var cnxIPv6 string + var cnxIPv4PortRange string go func() { defer wg.Done() log.Debug.Println("Collect connection") @@ -250,6 +252,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { cnxMedia = m.Media cnxIPv4 = m.IPv4 cnxIPv6 = m.IPv6 + cnxIPv4PortRange = fmt.Sprintf("%d-%d", m.IPv4PortRange[0], m.IPv4PortRange[1]) c.collectCounter(ch, m.RateUp, promDescConnectionRatesBytes, "tx") c.collectCounter(ch, m.RateDown, promDescConnectionRatesBytes, "rx") @@ -530,7 +533,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { cnxState, cnxMedia, cnxIPv4, - cnxIPv6) + cnxIPv6, + cnxIPv4PortRange) } func (c *Collector) collectXdslStats(ch chan<- prometheus.Metric, stats *fbx.MetricsFreeboxConnectionXdslStats, dir string) { diff --git a/fbx/get_metrics.go b/fbx/get_metrics.go index 0a69f1d..4dd0e0a 100644 --- a/fbx/get_metrics.go +++ b/fbx/get_metrics.go @@ -47,7 +47,7 @@ type MetricsFreeboxConnection struct { BandwidthDown *int64 `json:"bandwidth_down"` BytesUp *int64 `json:"bytes_up"` BytesDown *int64 `json:"bytes_down"` - // ipv4_port_range + IPv4PortRange []int64 `json:"ipv4_port_range"` } // MetricsFreeboxConnectionXdslStats https://dev.freebox.fr/sdk/os/connection/#XdslStats